I have a scroll layout with a relative layout in each line. Now is there an image and a text, and I want to limit the height of each line to the text.
So if my image is higher than the text, that the image will be resized to the height of the text (proportional). How can I do this in XML?
At the moment the line definition looks like (copied from the mumble android implementation):
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/RelativeLayout01"
android:layout_height="wrap_content"
android:layout_width="fill_parent">
<ImageView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:id="@+id/userRowState"
android:src="@drawable/icon" />
<TextView
android:layout_toLeftOf="@+id/userRowStatus"
android:layout_height="wrap_content"
android:text="[Name]"
android:id="@+id/userRowName"
android:ellipsize="end"
android:layout_width="wrap_content"
android:lines="1"
android:singleLine="true"
android:textSize="25sp"
android:layout_centerVertical="true"
android:layout_toRightOf="@+id/userRowState" />
<!--
singleLine is deprecated but it is the only way to get ellipsize work
it seems. 'inputType text, maxLines 1' didn't work. It's a known issue
that Google has开发者_Go百科 been unable to reproduce in 1½ years
http://code.google.com/p/android/issues/detail?id=882 Will see what
happens first, they remove support for singleLine or they manage to
reproduce the error. :p
-->
</RelativeLayout>
Sincerely xZise
You could try aligning the top and bottom of the icon to the top and bottom of the userRowName:
<ImageView
android:id="@+id/userRowState"
android:src="@drawable/icon"
android:layout_width="wrap_content"
android:layout_alignTop="@+id/userRowName"
android:layout_alignBottom="@+id/userRowName"/>
This should make it decrease in size when the text decreases. It will remain centered horizontally on its old position though and it won't grow as it's limited in horizontal direction.
精彩评论