Android 如何在滚动视图中放置Listview和Viewpager?
我有一个listview和viewpager,用于生成图像滑块。这两个有自己的适配器。在my layout.xml中,我想将它们放在滚动视图中,但当我这样做时,viewpager不会使用listview滚动。如果你有什么想法,可以帮我吗 谢谢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"
<?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。很高兴帮助您:)