我有一个滚动布局,每行都有相对布局。现在有一个图像和一个文本,我想将每行的高度限制为文本。
因此,如果我的图像高于文本,则图像将调整为文本的高度(比例)。我怎么能用XML做到这一点?
目前行定义看起来像(从mumble android实现中复制):
<?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 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>
真诚的xZise
答案 0 :(得分:0)
您可以尝试将图标的顶部和底部对齐到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"/>
这应该会在文本减少时减小大小。它将保持水平居中于旧位置,并且不会增长,因为它在水平方向上受限制。