2009-07-13 24 views
3

垂直填補我把一個ImageViewTextView被用作列表項的RelativeLayout內,並希望ImageView用的TextView行號垂直增長。可拖動的ImageView是豎條的圖片。如何使的ImageView內的RelativeLayout

通過以下佈局,認爲它在Eclipse的佈局視圖中看起來很好,ImageView在運行時沒有填充RelativeView的高度。相反,它始終保持原始圖片的高度。

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

爲什麼如我所料(或如在Eclipse佈局視圖)它不工作?

+0

如果您使用`android:background`而不是`android:src`它會改變什麼嗎? – Jakar 2012-04-06 05:34:42

回答

-1

我會做兩件事情:

  1. 通過TextView的一個「drawableLeft」合併簡化佈局。
  2. 使圖像成爲9色圖像,以便相應地增長。
1

我在你的代碼中做了一些改變。

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

現在它給出適當的輸出。 我做的是,首先聲明textview並將其與父級底部對齊。然後宣佈imageview並在textview的頂部alogned它。因此,imageview將在textview上方開始並取所有剩餘高度。我也測試過多行文本視圖。希望能幫助到你。

相關問題