Android Viewpager中的片段未向上滚动
我有一个由3个片段组成的viewpager。前两个片段只是recyclerViews,它们完美地向上滚动。但在我的第三个片段中,它是一个线性布局,不会向上滚动: 前两个片段布局只是回收器:Android Viewpager中的片段未向上滚动,android,Android,我有一个由3个片段组成的viewpager。前两个片段只是recyclerViews,它们完美地向上滚动。但在我的第三个片段中,它是一个线性布局,不会向上滚动: 前两个片段布局只是回收器: <?xml version="1.0" encoding="utf-8"?> <androidx.recyclerview.widget.RecyclerView xmlns:android="http://schemas.android.com/apk/res/android"
<?xml version="1.0" encoding="utf-8"?>
<androidx.recyclerview.widget.RecyclerView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
</androidx.recyclerview.widget.RecyclerView>
第三个未滚动的片段:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/backgroundColor"
android:orientation="vertical">
</LinearLayout>
我的viewpager布局:
<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.google.android.material.appbar.AppBarLayout
android:id="@+id/fragprofile_app_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/colorWhite"
android:orientation="vertical">
//Collapsing toolbar, etc
</com.google.android.material.appbar.AppBarLayout>
<androidx.viewpager.widget.ViewPager
android:id="@+id/fragprofile_viewpager"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/colorWhite"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>
//折叠工具栏等
为什么会发生这种情况?您应该将根
线性布局
替换为滚动视图
或嵌套滚动视图
注意1:默认情况下,Android布局不可滚动
注2:滚动视图
和嵌套滚动视图
必须只有一个直接子级(应该是某种布局,如线性布局
或约束布局
)
希望这有帮助。LinearLayout不是可滚动的视图组。您应该将线性布局放在
滚动视图
或嵌套滚动视图
中。