Android 在一个列表项中跨多个RelativeLayouts表示视图
我试图在一个列表项中有3个文本视图。挑战在于该列表项的格式类似于卡片,有两种不同的颜色(如图所示)。我通过创作2个不同的Android 在一个列表项中跨多个RelativeLayouts表示视图,android,xml,Android,Xml,我试图在一个列表项中有3个文本视图。挑战在于该列表项的格式类似于卡片,有两种不同的颜色(如图所示)。我通过创作2个不同的RelativeLayout完成了不同的颜色 我的XML正在正确格式化此列表项,但是它不包含所有3个视图。它最终创建了3个列表项2,其中2个只包含{view 2},另一个只包含{view 1}。是什么原因导致下面的XML没有将所有3个视图分组到一个列表项中?如何进行补救 <?xml version="1.0" encoding="utf-8"?> <Relat
RelativeLayout
完成了不同的颜色
我的XML正在正确格式化此列表项,但是它不包含所有3个视图。它最终创建了3个列表项2,其中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>
试试这个,我在您的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>
Cursor Cursor=getContentResolver().query(Uri.parse()content://sms/inbox)、空、空、空、空);
if(cursor.moveToFirst()){//必须检查结果以防止异常
做{
字符串msgData=“”;
对于(int idx=0;idx)您想要对齐文本或想要的卡片视图阴影?为什么不使用线性布局而不是相对布局??
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());
}