RecyclerView 在 ScrollView 中时不显示所有项目
RecyclerView does not showing all items when its in a ScrollView
我有 2 RecyclerViews
in a LinearLayout
inside a ScrollView
:
<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>
两个回收商都有 nestedScrollEnabled
flase 。
问题在这里:
当布局呈现时,第一个 recyclerView 将填充,屏幕底部的第二个 recyclerView 将不会显示所有项目,因为第一个高度!
但它应该滚动,因为它们都在 scrollView 中!
所以有什么问题吗?
尝试为两个 recycleViews 提供手册 height
,因为它们都在 scrollview
中,所以如果您提供 wrap_content
或 match_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>
使用NestedScrollView
代替ScrollView
并将 recyclerView.setNestedScrollingEnabled(false);
添加到您的 RecyclerView
我有 2 RecyclerViews
in a LinearLayout
inside a ScrollView
:
<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>
两个回收商都有 nestedScrollEnabled
flase 。
问题在这里: 当布局呈现时,第一个 recyclerView 将填充,屏幕底部的第二个 recyclerView 将不会显示所有项目,因为第一个高度! 但它应该滚动,因为它们都在 scrollView 中!
所以有什么问题吗?
尝试为两个 recycleViews 提供手册 height
,因为它们都在 scrollview
中,所以如果您提供 wrap_content
或 match_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>
使用NestedScrollView
代替ScrollView
并将 recyclerView.setNestedScrollingEnabled(false);
添加到您的 RecyclerView