2017-07-26 92 views
0

我試圖在一個列表項中有3個文本視圖。挑戰是這個列表項目被格式化爲一張卡片,有兩種不同的顏色(如圖所示)。我通過創意2不同的RelativeLayoutPictured here完成了不同的顏色。在一個列表項中代表幾個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> 
+0

? – akhilesh0707

+0

爲什麼不使用線性佈局而不是相對佈局? –

回答

0

試試這個我已經在你的XML

<?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="wrap_content" 
    android:orientation="vertical"> 


    <RelativeLayout 
     android:id="@+id/outer" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentStart="true" 
     android:layout_toLeftOf="@+id/button" 
     android:padding="5dp" 
     android:background="#08445e"> 

     <TextView 
      android:id="@+id/textViewRoom" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignParentLeft="true" 
      android:text="Room {room}" 
      android:textColor="#fff" /> 

     <TextView 
      android:id="@+id/textViewTime" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignParentRight="true" 
      android:text="Time: {Time} sec" 
      android:textColor="#fff" /> 

    </RelativeLayout> 

    <RelativeLayout 
     android:id="@+id/inner" 
     android:layout_width="match_parent" 
     android:layout_height="50dp" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentStart="true" 
     android:layout_below="@+id/outer" 
     android:layout_toLeftOf="@+id/button" 
     android:layout_toStartOf="@+id/button" 
     android:background="#d1d1d1"> 

     <TextView 
      android:id="@+id/textViewRequest" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_centerHorizontal="true" 
      android:layout_centerVertical="true" 
      android:textColor="#000" 
      android:text="{View 1}" 
      android:textSize="20sp" /> 

    </RelativeLayout> 

</LinearLayout> 
0
Cursor cursor = getContentResolver().query(Uri.parse("content://sms/inbox"), null, null, null, null); 

if (cursor.moveToFirst()) { // must check the result to prevent exception 
do { 
    String msgData = ""; 
    for(int idx=0;idx<cursor.getColumnCount();idx++) 
    { 
     msgData += " " + cursor.getColumnName(idx) + ":" + cursor.getString(idx); 
    } 
    // use msgData 
} while (cursor.moveToNext()); 
} 

一些變化可能這個代碼可以幫助你

要對齊文本或希望卡觀影
相關問題