Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/183.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 线性布局可与多个ListView一起滚动_Android_Listview - Fatal编程技术网

Android 线性布局可与多个ListView一起滚动

Android 线性布局可与多个ListView一起滚动,android,listview,Android,Listview,这是我的布局: <?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">

这是我的布局:

<?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">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="10dip"
        android:textSize="15sp"
        android:textStyle="bold"
        android:textColor="@android:color/holo_blue_dark"
        android:text="@string/section_1" />

    <ListView
        android:id="@+id/lv_section_1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:drawSelectorOnTop="false" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="10dip"
        android:textSize="15sp"
        android:textStyle="bold"
        android:textColor="@android:color/holo_blue_dark"
        android:text="@string/section_2" />

    <ListView
        android:id="@+id/lv_section_2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:drawSelectorOnTop="false" />

</LinearLayout>

问题是当第一部分有很多项目,并且占据了整个屏幕时,我无法滚动查看第二部分。通过快速搜索,我发现我无法在
ScollView
中使用
ListView

有没有办法让这个
LinearLayout
可以滚动,这样我就可以看到所有可以添加的部分?我需要一些类似iOS UITableView的东西,包括几个部分和标题


提前感谢。

对两个列表视图使用layout\u weight=“1”和layout\u height=“0dp”,这将把整个屏幕分成两部分,以便您可以同时看到这两个部分。如果您必须在listview顶部显示文本视图作为标题,然后选择两个具有上述权重的线性布局和内部线性布局,将文本视图和listview垂直放置。

好的,只是为了有一个包含多个部分的列表,我可以做些什么来解决我的问题非常简单:

我只留下了一个
ListView
,并创建了一个类
CustomAdapter
。并添加了不同类型的项目:

ArrayList<HashMap<String, String>> listItems = new ArrayList<HashMap<String, String>>();

HashMap map = new HashMap<String, String>();
map.put("type", "section");
map.put("title", "Section 1");
listItems.add(map);

map = new HashMap<String, String>();
map.put("type", "item");
map.put("title", "Item A");
map.put("detail", "Detail A");
listItems.add(map);
在my
CustomAdapter
中,我为每个类型、部分或项目设置了不同的样式。请注意,我只需要一些东西来区分
列表视图中的项目


如果我的解决方案太难看,仍然接受对此问题的建议:)

对于查看所有部分所有listView android:layout\u height=“Fixed size”没有包装内容…@MdAbdulGafur这样做,我无法滚动整个屏幕以查看第二部分。需要更多关于
线性布局的信息吗
?谢谢回复。你的意思是布局高度,对吗?好的,我这样做了,但是现在我有了屏幕分割,并且两个
ListView
都可以滚动。如果可能的话,我希望能够滚动整个屏幕,每个
ListView
都会显示出来,而不必单独滚动所有视图。不幸的是,这是不可能的,因为Android不支持滚动视图中的滚动视图。它没有显示错误,但仍然会产生糟糕的用户友好UI
CustomAdapter adapter = new CustomAdapter(context, R.layout.result_list, listItems);
ListView lv = (ListView) view.findViewById(R.id.resultlist);
lv.setAdapter(adapter);