【发布时间】:2018-03-23 19:21:36
【问题描述】:
我有一个带有 LinearLayout 的 ScrollView,里面还有几个不同的 RecyclerView,因为我从不同的来源加载数据。
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<android.support.v7.widget.RecyclerView
android:id="@+id/posts_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:color/white"
android:clipToPadding="false"
android:padding="10dp"
android:layout_marginTop="20dp"
android:nestedScrollingEnabled="false"/>
<android.support.v7.widget.RecyclerView
android:id="@+id/movies_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:color/white"
android:clipToPadding="false"
android:padding="10dp"
android:layout_marginTop="20dp"
android:nestedScrollingEnabled="false"/>
<android.support.v7.widget.RecyclerView
android:id="@+id/tv_shows_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:color/white"
android:clipToPadding="false"
android:padding="10dp"
android:layout_marginTop="20dp"
android:nestedScrollingEnabled="false"/>
<android.support.v7.widget.RecyclerView
android:id="@+id/music_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:color/white"
android:clipToPadding="false"
android:padding="10dp"
android:layout_marginTop="20dp"
android:nestedScrollingEnabled="false"/>
<android.support.v7.widget.RecyclerView
android:id="@+id/books_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:color/white"
android:clipToPadding="false"
android:padding="10dp"
android:layout_marginTop="20dp"
android:nestedScrollingEnabled="false"/>
</LinearLayout>
我同时使用 LinearLayoutManager 和 GridLayoutManager 来组织 recyclerviews 显示的内容。
GridLayoutManager layoutManager = new GridLayoutManager(context, 2);
recyclerView.setLayoutManager(layoutManager);
recyclerView.setAdapter(adapter);
由于某种原因,第二个 RecycleView(带有 GridLayout)的最后一个元素被截断了。
而其他 RecycleViews 的元素以正确的方式显示。
我不知道它是否重要,但在 RecycleViews 中我使用 CardViews。
任何帮助都将不胜感激,因为我正在为这个问题发疯:(
解决方案
解决方案很简单:我只是使用 NestedScrollView 而不是 ScrollView,它工作正常。
【问题讨论】:
-
stackoverflow.com/q/27083091/5132444 这应该对你有帮助。
-
只是一个建议,我认为您应该考虑将
RecyclerView与水平Layoutmanager一起用于除Grid之外的这种类型的排列。 -
答案可以在[RecyclerView inside ScrollView is not working](stackoverflow.com/q/27083091/5132444)
-
@MattiaCampana np,您能否将答案标记为正确,以便未来的观众可以直接看到帖子。
标签: android android-layout android-recyclerview scrollview