Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/url/2.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 在一个LinearLayout内滚动两个listview_Android_Android Layout_Android Listview_Android Xml_Android Scrollview - Fatal编程技术网

Android 在一个LinearLayout内滚动两个listview

Android 在一个LinearLayout内滚动两个listview,android,android-layout,android-listview,android-xml,android-scrollview,Android,Android Layout,Android Listview,Android Xml,Android Scrollview,我试图滚动一个线性布局内的listview,但它不是我想要的工作。我附上一张图片作进一步解释。 这是我的布局 <android.support.v7.widget.CardView android:id="@+id/card" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layou

我试图滚动一个线性布局内的listview,但它不是我想要的工作。我附上一张图片作进一步解释。 这是我的布局

 <android.support.v7.widget.CardView
            android:id="@+id/card"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_gravity="center"
            android:clickable="false"
            app:cardBackgroundColor="@android:color/white"
            app:cardElevation="2dp"
            app:cardPreventCornerOverlap="false"
            app:cardUseCompatPadding="false">

            <ScrollView
                android:layout_width="fill_parent"
                android:layout_height="fill_parent">

                <LinearLayout
                    android:layout_width="fill_parent"
                    android:layout_height="fill_parent"
                    android:orientation="vertical">

                    <ListView
                        android:id="@+id/listView1"
                        android:layout_width="fill_parent"
                        android:layout_height="wrap_content" />

                    <ListView
                        android:id="@+id/list"
                        android:layout_width="fill_parent"
                        android:layout_height="wrap_content"

                        />


                    <LinearLayout
                        android:layout_width="match_parent"
                        android:layout_height="0dip"
                        android:layout_weight="1"
                        android:gravity="center|bottom"
                        android:orientation="vertical">

                        <Button
                            android:id="@+id/findSelected"
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:layout_gravity="center_horizontal|center"
                            android:background="@drawable/flat_selector_green"
                            android:text="Next"
                            android:textColor="@android:color/white" />
                    </LinearLayout>

                </LinearLayout>
            </ScrollView>


        </android.support.v7.widget.CardView>


我知道使用listview不是一个好方法,但我必须这样做。

只需从xml代码中删除ScrollView,因为listview有自己的滚动条,不需要ScrollView。然后代码就可以按照您的需要工作。在显示第一个ListView的每个项目后,将显示第二个列表

根据android文档

您不应该在ListView中使用,因为ListView负责自己的垂直滚动。最重要的是,这样做会破坏ListView中处理大型列表的所有重要优化,因为它有效地迫使ListView显示其整个项目列表,以填充ScrollView提供的无限容器

首先您将用户卡视图作为顶级父级,似乎您将使用它作为列表视图的子级,正如我所猜测的,如果我的猜测是正确的,那么使用两个列表视图作为子级是不明智的

Second在任何情况下,如果希望在同一视图中使用两个listview,建议使用view(文本视图,…等)将它们分开

解决方案

1-删除卷轴,因为它无用

2-将权重添加到列表视图中,因为案例中的包装内容意味着整个视图

3-建议添加视图以分隔列表

 <android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/card"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center"
android:clickable="false"
app:cardBackgroundColor="@android:color/white"
app:cardElevation="2dp"
app:cardPreventCornerOverlap="false"
app:cardUseCompatPadding="false">


    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/wholeview"
        >

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            android:weightSum="2">

        <ListView
            android:id="@+id/listView1"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1"

        />
            <!-- recommended to add view here -->

        <ListView
            android:id="@+id/list"
            android:layout_width="fill_parent"
            android:layout_height="0dp"
            android:layout_weight="1"
            />
        </LinearLayout>
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true">
            <Button
                android:id="@+id/findSelected"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_gravity="center_horizontal|center"
                android:text="Next"
                android:textColor="@android:color/white"
                />
        </LinearLayout>
        </RelativeLayout>


您的意思是希望列表1和项目1,2列表2和项目3,4,5,6,7=>列表1,2,3,4,5,6,7吗?@tinysunlight是的,我希望所有值首先滚动,然后第二个列表元素是滚动为什么需要
滚动视图
<代码>列表视图
s独立滚动。您可以将所有数据放在一个列表中。为什么不将它们放在一起?@MikeM。当我删除scrollview时,我的第二个列表是scroll,但不是firstthanks@Gaurav,但当我删除scroll View时,我的第二个列表是scroll,但不是firstthanks@MinaFawzy,但当我尝试此解决方案时,我的listview被分为两部分,我希望列表将再次滚动第一个列表在第一部分滚动,第二个列表在第二部分滚动第二部分,但实际上我希望我的第一个列表滚动完成,然后我的第二个自动滚动为什么你不把所有元素放在一个列表视图中,然后实际上我正在处理一个旧项目,其中两个选项卡被维护,两个列表被维护,但现在项目更改的要求是删除选项卡并显示单个列表现在问题是这两个列表具有不同的适配器和型号,并且所选的项目已转到不同的url。