2012-05-11 26 views
0

我需要建立類似於以下佈局:的Android的TextView FILL_PARENT

Desired layout

的三排左邊是TextViews,其總高度爲開頭未知。右側的元素應該是任何可以動態更改其背景色的控件。它應該跨越其高度來填補父母。

我該如何做到這一點?我應該使用什麼小部件來顯示顏色?什麼佈局?

我嘗試使用正確的元素TextView以下,但它不會填充父項。

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" > 

<TextView 
    android:id="@+id/txtRow_color" 
    android:layout_width="10dip" 
    android:layout_height="fill_parent" 
    android:layout_alignParentRight="true" 
    android:layout_alignParentTop="true" 
    android:layout_alignParentBottom="true" 
    android:background="#ff23cf"  
    android:text="" /> 

    <TextView 
     android:id="@+id/txtRow_name" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentTop="true" 
     android:layout_toLeftOf="@id/txtRow_color" 
     android:textColor="#FFFF66" 
     android:text="@string/nullstring" /> 

    <TextView 
     android:id="@+id/txtRow_Tweet" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentBottom="true" 
     android:layout_below="@id/txtRow_name" 
     android:layout_toLeftOf="@id/txtRow_color" 
     android:layout_alignWithParentIfMissing="true" 
     android:gravity="center_vertical" 
     android:text="@string/nullstring" /> 

</RelativeLayout> 

回答

1

可以嘗試

<?xml version="1.0" encoding="utf-8"?> 

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" android:layout_height="wrap_content" 
    android:orientation="horizontal" android:weightSum="1"> 

    <LinearLayout android:layout_width="0dp" 
     android:layout_height="wrap_content" android:orientation="vertical" 
     android:layout_weight=".8"> 
     <TextView android:id="@+id/te" android:layout_width="wrap_content" 
      android:layout_height="wrap_content" android:text="Text1" /> 
     <TextView android:id="@+id/tile" android:layout_width="wrap_content" 
      android:layout_height="wrap_content" android:text="Text2" /> 
     <TextView android:id="@+id/e" android:layout_width="wrap_content" 
      android:layout_height="wrap_content" android:text="Text3" /> 

    </LinearLayout> 

    <LinearLayout android:layout_width="0dp" 
     android:layout_height="fill_parent" android:layout_weight=".2" 
     android:background="@color/green"> 

    </LinearLayout> 
</LinearLayout> 
+0

它做到了! LinearLayout是解決方案。謝謝! – thameera

0

你很可能將不得不使用兩個嵌套LinearLayouts,這樣的事情,我只是存根它與一些重要的屬性:

<LinearLayout android:orientation= "horizontal"> 
    <LinearLayout android:orientation= "vertical" android:layout_height="fill_parent"> 
    <TextView android:layout_width="fill_parent" /> 
    <TextView android:layout_width="fill_parent" /> 
    <TextView android:layout_width="fill_parent" /> 
    </LinearLayout> 
    <ImageView android:layout_height="fill_parent" /> 
</LinearLayout> 

由於您只是顯示純色,因此還有其他一些視圖可以代替圖像視圖,這只是一個示例。您可以在ImageView上使用setBackgroundColor()來更改它的顏色。

+0

謝謝。我使用另一種解決方案中提到的LinearLayout,它工作。 – thameera