2017-07-26 42 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()); 
} 

一些变化可能这个代码可以帮助你

要对齐文本或希望卡观影
相关问题