在一行中有文本视图和图像。我需要按比例拉伸图像,使其与文本视图的高度相同。怎么做?如何在布局中将图像拉伸到行高?
这就是布局:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/RelativeLayout1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_toLeftOf="@+id/imageView1"
android:text="Medium Text"
android:textAppearance="?android:attr/textAppearanceMedium" />
<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:adjustViewBounds="true"
android:cropToPadding="true"
android:src="@drawable/ic_launcher" />
</RelativeLayout>
布局重量是不是我想要的:它从总宽度花费%。我需要的是保持不变的高度,例如weight == 0.0 – Exterminator13
将textview,imageview包含到linearlayout中,并为textview设置android:layout_height =“fill_parent”,为textview设置android:layout_height =“wrap_content” –
只需使用layout_alignTop和layout_alignBottom将您的视图从Top和Bottom对齐到有相同的高度 – Houcine