Android 列表视图图像大小
我的列表视图有问题,其中每个项目都包含一个 ImageView 和一些 TextView 。
或多或少,有两行 TextView 和一个 ImageView (XX),应该占用这两行:
|XX| TextView 1 TextView 2
|XX| TextView 3 TextView 4
我的问题是当我更改 ImageView 中的图像时。我的目标是使图像视图与两个文本视图具有相同的高度。但我的图像是 400x300,图像视图被扩展以包含它。我尝试使用 getHeight 或 getMeasuredHeight 获取 imageView 的高度来调整位图大小,然后再将其放入 imageView 中,但它不起作用。
我的列表视图布局是:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<ImageView
android:id="@+id/list_poi_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:scaleType="centerCrop"
android:contentDescription="@string/points_of_interest_activity_image_content_description" />
<TextView
style="@style/CarloText"
android:id="@+id/list_poi_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_toRightOf="@+id/list_poi_image"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
style="@style/CarloText"
android:id="@+id/list_poi_description"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/list_poi_name"
android:layout_below="@+id/list_poi_name"
android:textAppearance="?android:attr/textAppearanceMedium" />
...
感谢您的帮助!
I have a problem with my listview which contains an ImageView and a few TextView for each item.
More or less, there are two lines of TextViews and one ImageView (XX) that should take the two lines :
|XX| TextView 1 TextView 2
|XX| TextView 3 TextView 4
My problem is when I change the image in the ImageView. My goal is to have the same height for the imageview as for the two textviews together. But my image being 400x300, the imageview is expanded to contain it. I tried to get the height of the imageView with getHeight or getMeasuredHeight to resize the bitmap before putting it in the imageView, it does not work.
My layout for the listview is:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<ImageView
android:id="@+id/list_poi_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:scaleType="centerCrop"
android:contentDescription="@string/points_of_interest_activity_image_content_description" />
<TextView
style="@style/CarloText"
android:id="@+id/list_poi_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_toRightOf="@+id/list_poi_image"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
style="@style/CarloText"
android:id="@+id/list_poi_description"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/list_poi_name"
android:layout_below="@+id/list_poi_name"
android:textAppearance="?android:attr/textAppearanceMedium" />
...
Thanks for you help !!!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
为imageview设置一些固定的高度,并设置imageView的缩放类型FIT_XY或CENTER_INSIDE。 FIT_XY 会将图像缩放到所需的宽度和高度,而不管长宽比如何,因此图像可能会拉伸,CENTER_INSIDE 会在给定尺寸中缩放图像,保持图像的长宽比,因此图像可能看起来比可用空间小。
Set some fixed height to imageview, and set scale type of imageView FIT_XY or CENTER_INSIDE. FIT_XY will scale your image to desired width and height, irrespective of aspect ration, so image may stretch, CENTER_INSIDE will scale your image in given dimensions maintaining aspect ratio of image, so image may look samaller than available space.
您可以在代码中设置
ImageView
的LayoutParams
,使其高度等于TextView1
+TextView3
。You could set the
LayoutParams
of theImageView
in code to make it have a height equal toTextView1
+TextView3
.