我有一个用于ListView单元格的简单线性布局,并且它包含一个ImageView。图片将从互联网下载,因此大小可以不同。
然而,我想将ImageView的宽度设置为fill_parent,即固定的宽度,并在运行时动态更改图像高度。设置图像高度的规则如下:如果图像的高/宽比大于1,则使ImageView正方形,即将其高度与宽度匹配。
如果图像的高/宽比小于1,则按比例调整大小。以下是两个预期样本。
第一个样本的h/w < 1,而第二个样本'Cat'的h/w > 1。
谢谢你的时间。
然而,我想将ImageView的宽度设置为fill_parent,即固定的宽度,并在运行时动态更改图像高度。设置图像高度的规则如下:如果图像的高/宽比大于1,则使ImageView正方形,即将其高度与宽度匹配。
如果图像的高/宽比小于1,则按比例调整大小。以下是两个预期样本。
第一个样本的h/w < 1,而第二个样本'Cat'的h/w > 1。
谢谢你的时间。
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@color/white"
android:orientation="vertical"
android:padding="10dp" >
<TextView
android:id="@+id/postTitle"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:ellipsize="end"
android:maxLines="2"
android:textColor="@color/black"
android:textSize="18sp"
android:textStyle="bold" />
<ImageView
android:id="@+id/postImg"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:scaleType="centerCrop"
android:src="@drawable/dummy_image"
android:contentDescription="@string/postImage" />
</LinearLayout>