簡體   English   中英

用LinearLayout子級填充RelativeLayout父級

[英]Fill RelativeLayout parent with LinearLayout child

這似乎很簡單,但是我已經用盡了Google搜索的耐心。

我有一個RelativeLayout ,它具有兩個並排的子LinearLayout ,並且無論兩個LinearLayouts的高度如何,我都希望它們都垂直填充父級。 這被用作ListView行, @ id / item_left下的內容通常短於右邊的內容。

背景可繪制對象不會填滿整個行。

關於讓雙方都滿意的任何想法嗎?

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="fill_parent">
    <LinearLayout android:id="@+id/item_left"
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        android:paddingRight="2dp"
        android:paddingLeft="2dp"
        android:background="@drawable/item_left"
        android:orientation="vertical">
        <TextView android:id="@+id/time"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textColor="@color/item_left_text"
            android:text="" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        android:background="@color/item_right_background"
        android:layout_toRightOf="@id/item_left">           
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textColor="@color/item_right_text"
            android:text="Row1" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textColor="@color/item_right_text"
            android:text="Row2" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textColor="@color/item_right_text"
            android:text="Row3" />
    </LinearLayout>
</RelativeLayout>

嘗試這段代碼....對不起,但我將顏色更改為當您更改第一個TextView的文本時的影響

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent" android:layout_height="fill_parent"
    android:background="#ffffffff" android:weightSum="1">

    <LinearLayout android:id="@+id/item_left"
        android:layout_width="wrap_content" android:layout_height="fill_parent"
        android:paddingRight="2dp" android:paddingLeft="2dp"
        android:background="#ff0000ff" android:orientation="vertical" >
        <TextView android:id="@+id/time" android:layout_width="wrap_content"
            android:layout_height="wrap_content" android:textColor="#ff555555"
            android:text="sdfdsf s ada d a   asd sad sad"  />
    </LinearLayout>

    <LinearLayout android:layout_width="wrap_content"
        android:layout_height="match_parent" android:orientation="vertical"
        android:background="#ffff0000" 
        android:layout_weight="1" >
        <TextView android:layout_width="wrap_content"
            android:layout_height="wrap_content" android:textColor="#ff555555"
            android:text="Row1" />

        <TextView android:layout_width="wrap_content"
            android:layout_height="wrap_content" android:textColor="#ff00ff00"
            android:text="Row2" />

        <TextView android:layout_width="wrap_content"
            android:layout_height="wrap_content" android:textColor="#ff00ff00"
            android:text="Row3" />
    </LinearLayout>


</LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <LinearLayout
        android:id="@+id/layout1"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:orientation="vertical"
        android:background="#FF0000">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="helloooooooooooooo" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_toRightOf="@id/layout1"
        android:background="#0000FF"

 >

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Row1" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Row2" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Row3" />
    </LinearLayout>
</RelativeLayout>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM