如何在android布局的片段中添加两个ListView?
我试图在一个片段中显示两个列表视图。但我在xml文件本身中遇到了问题。我用的是夏洛克碎片。 此外,一个列表应显示在屏幕的2/3空间上,另一个列表应显示在屏幕的1/3空间上。你能帮忙吗?任何帮助都将不胜感激。提前谢谢如何在android布局的片段中添加两个ListView?,android,xml,listview,Android,Xml,Listview,我试图在一个片段中显示两个列表视图。但我在xml文件本身中遇到了问题。我用的是夏洛克碎片。 此外,一个列表应显示在屏幕的2/3空间上,另一个列表应显示在屏幕的1/3空间上。你能帮忙吗?任何帮助都将不胜感激。提前谢谢 <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android
<?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"
android:background="#DEF7C6"
android:orientation="vertical" >
<RelativeLayout
android:id="@+id/layout1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<ImageView
android:layout_width="60dp"
android:layout_height="35dp"
android:paddingLeft="0dp"
android:src="@drawable/search" />
<EditText
android:id="@+id/EditText01"
android:layout_width="280dp"
android:layout_height="wrap_content"
android:hint="Search"
android:paddingLeft="50dp"
android:textColor="#000000" >
</EditText>
<ListView
android:id="@android:id/list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/EditText01"
android:drawSelectorOnTop="false"
android:listSelector="@android:color/darker_gray" >
</ListView>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="2"
android:background="#CFCACC" >
</RelativeLayout>
</RelativeLayout>
<RelativeLayout
android:id="@+id/layout2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@id/layout1"
android:layout_weight="2" >
<FrameLayout
android:id="@+id/fragment_container"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:textColor="#000000" />
</RelativeLayout>
<Button
android:id="@+id/addbutton"
android:layout_width="42dp"
android:layout_height="41dp"
android:layout_above="@+id/list"
android:layout_alignParentRight="true"
android:background="@drawable/buttonadd" />
</RelativeLayout>
以下是仅用于列表视图的代码:
<?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="match_parent"
android:background="#DEF7C6"
android:orientation="vertical" >
<ListView
android:id="@+id/list1"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="2"
android:drawSelectorOnTop="false"
android:entries="@array/l1"
android:listSelector="@android:color/darker_gray" >
</ListView>
<ListView
android:id="@+id/list2"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:drawSelectorOnTop="false"
android:entries="@array/l2"
android:listSelector="@android:color/darker_gray" >
</ListView>
</LinearLayout>
注意“重量”参数以达到2/3-1/3的比例。如果要动态添加列表视图元素,应该查看
如果您想要其他元素而不是第二个
列表视图
,只需将其更改为线性布局
或相对布局我疯了还是上面只有一个列表视图?