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 !!!
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.