我試圖在一個列表項中有3個文本視圖。挑戰是這個列表項目被格式化爲一張卡片,有兩種不同的顏色(如圖所示)。我通過創意2不同的RelativeLayout
完成了不同的顏色。在一個列表項中代表幾個RelativeLayouts的視圖
我的XML正在格式化此列表項目,但它不包含所有3個視圖。它最終創建3個列表項目2,其中僅包含{view 2}
,另一個僅包含{view 1}
。是什麼導致下面的XML不將所有3個視圖組合到一個列表項中,以及如何修復它?
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:padding="2dp"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="80dp"
android:layout_height="wrap_content"
android:id="@+id/outer"
android:padding="3dp"
android:background="#08445e"
android:layout_toLeftOf="@+id/button"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true">
<TextView
android:id="@+id/textViewRoom"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Room "
android:textColor="#fff"
android:layout_alignParentLeft="true"/>
<TextView
android:id="@+id/textViewTime"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Time: "
android:layout_alignParentRight="true"
android:textColor="#fff" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="50dp"
android:id="@+id/inner"
android:background="#d1d1d1"
android:layout_below="@+id/outer"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_toLeftOf="@+id/button"
android:layout_toStartOf="@+id/button">
<TextView
android:id="@+id/textViewRequest"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:textColor="#000"
android:textSize="20sp"
android:layout_centerHorizontal="true" />
</RelativeLayout>
</RelativeLayout>
? – akhilesh0707
爲什麼不使用線性佈局而不是相對佈局? –