如何在同一个布局上放置两个或更多listview?

时间:2011-02-24 15:13:55

标签: android listview layout android-listview android-linearlayout

我试过这段代码:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
     android:orientation="vertical" android:layout_width="fill_parent"
     android:layout_height="fill_parent">

     <LinearLayout android:orientation="horizontal"
          android:layout_width="fill_parent" 
          android:layout_height="fill_parent"
          android:layout_weight="1">

          <ListView 
                android:id="@+id/List1" 
                android:layout_width="fill_parent"
                android:layout_height="fill_parent" 
                android:layout_weight="1" />

          <ListView 
                android:id="@+id/List2" 
                android:layout_width="fill_parent"
                android:layout_height="fill_parent" 
                android:layout_weight="1" />

          <ListView 
                android:id="@+id/List3" 
                android:layout_width="fill_parent"
                android:layout_height="fill_parent" 
                android:layout_weight="1" />

          <ListView 
                android:id="@+id/List4" 
                android:layout_width="fill_parent"
                android:layout_height="fill_parent" 
                android:layout_weight="1" />
     </LinearLayout>
</LinearLayout>

没有成功。这样做有效,但我不想为所有列表划分x屏幕,我想扩展每个列表的width并使其可以在x轴上滚动。 。 有谁知道我能做到吗?

1 个答案:

答案 0 :(得分:4)

这是可能的。在您的情况下,它不起作用,因为android:layout_width设置为fill_parent,因此第一个布局将占用所有可用空间。尝试为每个android:layout_weight="1"提供ListView。并删除不必要的内部LinearLayouts

这对我有用:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
     android:orientation="horizontal"
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent"
     android:layout_weight="1">

     <ListView 
          android:id="@+id/List1" 
          android:layout_width="fill_parent"
          android:layout_height="fill_parent" 
          android:layout_weight="1" />

     <ListView 
          android:id="@+id/List2" 
          android:layout_width="fill_parent"
          android:layout_height="fill_parent" 
          android:layout_weight="1" />
</LinearLayout>

我刚刚接受了您的代码并删除了两个列表视图:

enter image description here

相关问题