How to make ImageView vertical within RelativeLayout

I put the ImageView and TextView in a RelativeLayout , which is used as list items, and I want the ImageView grow vertically with the line number of the TextView . Derived from ImageView is a png image of a vertical bar.

With the following layout, I thought that it looks great in the Layout view in Eclipse, the ImageView does not fill the height of the RelativeView at runtime. Instead, it always retains the original image height.

 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" > <ImageView android:id="@+id/iv" android:layout_width="wrap_content" android:layout_height="fill_parent" android:layout_alignParentLeft="true" android:src="@drawable/vbar" android:adjustViewBounds="false" android:scaleType="fitXY"/> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:singleLine="false" android:layout_toRightOf="@id/iv" android:layout_alignParentBottom="true" /> </RelativeLayout> 

Why doesn't this work as I expect (or as shown in the Layout Layout view)?

+4
source share
2 answers

I made some changes to your code.

 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" > <TextView android:id="@+id/tv" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:singleLine="false" android:text="@string/text" /> <ImageView android:id="@+id/iv" android:layout_width="wrap_content" android:layout_height="match_parent" android:layout_alignParentLeft="true" android:layout_above="@id/tv" android:adjustViewBounds="false" android:scaleType="fitXY" /> </RelativeLayout> 

Now he gives the correct conclusion. I did this, first declared a textview and aligned it with the parent bottom. Then an image was announced and recognized on the top of the text. Thus, the image will start just above the text field and display the entire remaining height. I also tested multiline text. Hope this helps.

+1
source

I would do a couple of things:

  • Simplify the layout by combining a TextView with "drawableLeft".
  • Make the image 9-patch image so that it matches.
-1
source

All Articles