Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/215.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和Viewpager?_Android_Listview_Android Viewpager_Scrollview - Fatal编程技术网

Android 如何在滚动视图中放置Listview和Viewpager?

Android 如何在滚动视图中放置Listview和Viewpager?,android,listview,android-viewpager,scrollview,Android,Listview,Android Viewpager,Scrollview,我有一个listview和viewpager,用于生成图像滑块。这两个有自己的适配器。在my layout.xml中,我想将它们放在滚动视图中,但当我这样做时,viewpager不会使用listview滚动。如果你有什么想法,可以帮我吗 谢谢 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

我有一个listview和viewpager,用于生成图像滑块。这两个有自己的适配器。在my layout.xml中,我想将它们放在滚动视图中,但当我这样做时,viewpager不会使用listview滚动。如果你有什么想法,可以帮我吗

谢谢

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

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical"
            android:id="@+id/test">

            <android.support.v4.view.ViewPager xmlns:android="http://schemas.android.com/apk/res/android"
                android:id="@+id/pager_news"
                android:layout_width="match_parent"
                android:layout_height="0dp"
                android:layout_weight="1" />

            <ListView
                android:id="@+id/news_lw"
                android:layout_width="match_parent"
                android:layout_height="0dp"
                android:layout_weight="2"
                android:nestedScrollingEnabled="true">

            </ListView>
        </LinearLayout>

    </LinearLayout>

列表视图
不支持嵌套滚动。因此,如果您认为有必要使用
NestedScrollView
RecyclerView
,则可以使用
NestedScrollView


更好的方法是使用
协调器布局
,并定义一个自定义行为,如果
循环视图
被滚动一个特定的扩展,则该行为可将
查看页面
滚入或滚出。

列表视图
不支持嵌套滚动。因此,如果您认为有必要使用
NestedScrollView
RecyclerView
,则可以使用
NestedScrollView


更好的做法是使用
协调布局
,并定义一个自定义行为,如果
循环视图
被滚动一个特定的扩展,则该行为将
查看页面
滚入或滚出。

嵌套滚动视图
循环视图
一起使用,而不是
列表视图

试试这个:

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

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

        <android.support.v4.view.ViewPager
            android:id="@+id/pager_news"
            android:layout_width="match_parent"
            android:layout_height="200dp" />

        <android.support.v7.widget.RecyclerView
            android:id="@+id/news_lw"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_below="@id/pager_news">

        </android.support.v7.widget.RecyclerView>
    </RelativeLayout>

</android.support.v4.widget.NestedScrollView>

嵌套滚动视图
回收视图
一起使用,而不是
列表视图

试试这个:

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

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

        <android.support.v4.view.ViewPager
            android:id="@+id/pager_news"
            android:layout_width="match_parent"
            android:layout_height="200dp" />

        <android.support.v7.widget.RecyclerView
            android:id="@+id/news_lw"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_below="@id/pager_news">

        </android.support.v7.widget.RecyclerView>
    </RelativeLayout>

</android.support.v4.widget.NestedScrollView>


将NestedScrollView与协调器布局一起使用NestedScrollView与协调器布局一起使用这只是一个示例。您也可以使用LinearLayout。很高兴为您提供帮助:)这只是一个示例。您也可以使用LinearLayout。很高兴帮助您:)