【问题标题】:RecyclerView does not showing all items when its in a ScrollViewRecyclerView 在 ScrollView 中不显示所有项目
【发布时间】:2018-09-30 01:48:41
【问题描述】:

我在LinearLayout 中有两个RecyclerViewsScrollView 中:

<ScrollView
    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"
    android:padding="@dimen/few_value">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">

        <com.foodjoo.fjco.customViews.BYekanFontText
            android:id="@+id/market_category"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="right"
            android:padding="@dimen/normal_plus_value"
            android:text=" لبنیات > مارکت پیکی علی  "
            android:textAppearance="@style/Base.TextAppearance.AppCompat.Subhead"
            android:textColor="@color/light_black2" />

        <android.support.v7.widget.RecyclerView
            android:id="@+id/market_cat_recycler"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />

        <com.foodjoo.fjco.customViews.BYekanFontText
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="right"
            android:padding="@dimen/normal_plus_value"
            android:text="ساعات کار"
            android:textAppearance="@style/Base.TextAppearance.AppCompat.Subhead"
            android:textColor="@color/light_black2" />

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

    </LinearLayout>
</ScrollView>

两个回收站都有nestedScrollEnabledflase。

问题在这里: 当布局渲染时,第一个 recyclerView 将被填充,屏幕底部的第二个 recyclerView 不会显示所有项目,因为第一个高度! 但它应该滚动,因为它们都在 scrollView 中!

那么问题是什么?

【问题讨论】:

  • 你试过移除滚动视图吗?
  • 尝试将第二个回收站视图的高度设置为 wrap_content
  • @PierGiorgioMisley 我需要 scrollView 来滚动页面,它不能被移除
  • @ShubhamSrivastava 仍然无法正常工作:(
  • 你也可以发布你的活动吗!

标签: android android-layout android-recyclerview nestedrecyclerview


【解决方案1】:

使用NestedScrollView而不是ScrollView

并将recyclerView.setNestedScrollingEnabled(false); 添加到您的RecyclerView

【讨论】:

  • 不错的解决方案!谢谢
【解决方案2】:

尝试为两个 recycleViews 提供手动 height,因为它们都在 scrollview 中,所以如果你提供 wrap_contentmatch_parent,它将不起作用。

<ScrollView
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"
android:padding="5dp">

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical">

    <com.foodjoo.fjco.customViews.BYekanFontText
        android:id="@+id/market_category"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="right"
        android:padding="@dimen/normal_plus_value"
        android:text=" لبنیات > مارکت پیکی علی  "
        android:textAppearance="@style/Base.TextAppearance.AppCompat.Subhead"
        android:textColor="@color/light_black2" />

    <android.support.v7.widget.RecyclerView
        android:id="@+id/market_cat_recycler"
        android:layout_width="match_parent"
        android:layout_height="500dp" />

    <com.foodjoo.fjco.customViews.BYekanFontText
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="right"
        android:padding="@dimen/normal_plus_value"
        android:text="ساعات کار"
        android:textAppearance="@style/Base.TextAppearance.AppCompat.Subhead"
        android:textColor="@color/light_black2" />

    <android.support.v7.widget.RecyclerView
        android:id="@+id/market_hours_recycler"
        android:layout_width="match_parent"
        android:layout_height="500dp" />

</LinearLayout>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-09-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多