2012-10-11 31 views
0

在一行中有文本视图和图像。我需要按比例拉伸图像,使其与文本视图的高度相同。怎么做?如何在布局中将图像拉伸到行高?

这就是布局:

<?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> 

回答

1

使用只是使用layout_alignToplayout_alignBottom顶部底部对准你的意见,以具有相同的高度

0

尝试使用android:layout_weight。重量只能在LinearLayout

+0

布局重量是不是我想要的:它从总宽度花费%。我需要的是保持不变的高度,例如weight == 0.0 – Exterminator13

+0

将textview,imageview包含到linearlayout中,并为textview设置android:layout_height =“fill_parent”,为textview设置android:layout_height =“wrap_content” –

+1

只需使用layout_alignTop和layout_alignBottom将您的视图从Top和Bottom对齐到有相同的高度 – Houcine

3

在您的ImageView

试试这个代码

android:layout_alignBottom =“@ + id/textView1”

代替

机器人:layout_centerVertical = “真”