【问题标题】:RecyclerViews inside ScrollView is cutting off the last itemScrollView 内的 RecyclerViews 正在切断最后一项
【发布时间】: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,它工作正常。

【问题讨论】:

标签: android android-layout android-recyclerview scrollview


【解决方案1】:

在这种情况下使用嵌套滚动视图而不是滚动视图。

【讨论】:

    【解决方案2】:

    在线性布局上设置下边距将解决您的问题。下边距应该是回收站视图行的高度大小。

    【讨论】:

      猜你喜欢
      • 2015-12-20
      • 1970-01-01
      • 2016-02-25
      • 1970-01-01
      • 1970-01-01
      • 2020-08-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多