- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我是一个新的 android 程序员。我想用 PullToRefreshListView
显示图像,但我发现 ImageView
的左侧和右侧都有空白。我已经尝试了一些关于“ImageView 空白区域”的解决方案,包括使用 adjustViewBounds="true"
和 scaleType
,但它失败了。以下代码是我的列表单元格布局。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<LinearLayout android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<LinearLayout android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="@+id/location"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ImageView
android:id="@+id/userPortrait"
android:layout_width="30dp"
android:layout_height="30dp"
android:src="@drawable/ic_launcher"
/>
<TextView
android:id="@+id/userName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
</LinearLayout>
</LinearLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
/>
<TextView
android:id="@+id/timeAgo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20px"
android:layout_marginRight="5px"
/>
</LinearLayout>
<!-- here is my imageControl -->
<ImageView
android:id="@+id/imageUrl"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="fitCenter"
android:adjustViewBounds="true"
/>
</LinearLayout>
图片来自服务器,所以我通过imageView.setImageBitmap
在代码中添加了图片源。我也试过使用imageView.setBackground(drawable)
,其实左右两边都没有出现空白,但是高度不对,不依赖于宽高比。
有人能帮帮我吗?提前致谢。
最佳答案
如果 ImageView
布局后的纵横比与图像本身的纵横比不同,你必须做出选择:
ImageView
并留出一些空间(在您的例子中,左侧和右侧),请使用 android:scaleType="fitCenter"
。 ImageView
并裁剪图像(在你的例子中,在顶部和底部),使用 android:scaleType="cropCenter"
ImageView
尺寸,请使用 android:scaleType="fitXY "
.android:adjustViewBounds="true"
是这样工作的:当你有一个维度的 ImageView
“固定”(例如 match_parent
或 240dp
等)和另一个维度“灵活”(例如 wrap_content
),设置 android:adjustViewBounds="true"
将导致 ImageView
布局使 wrap_content
尺寸恰到好处,以匹配源图像的纵横比。
由于您在 ImageView
的两个维度上都有 match_parent
,android:adjustViewBounds="true"
不会有任何效果。
关于java - 使用adjustViewBounds和scaleType后ImageView左右两边仍然出现空白,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31017690/
我目前正在编写一份报告,其中包含从 Web 服务注入(inject)的数据。该网络服务向其发送“双重?”允许空值。在报告中,它显示返回的值,这些值稍后用于对数字进行求和和平均。我的问题在于显示值的表达
我是一名优秀的程序员,十分优秀!