一个活动滚动问题中的两个回收视图

卡齐哈桑 |

我在一项活动中创建了 2 个回收视图。一个水平滚动,而另一个垂直滚动。我可以在每个 RecyclerView 内正确滚动,但整个页面不会滚动,即顶部 RecyclerView 始终位于顶部,底部始终位于底部,就像两者都固定在适当的位置。

<ScrollView 
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="com.shakeelnawaz.recipes.AllRecipesFragmet">

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

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginBottom="10dp"
        android:layout_marginStart="20dp"
        android:layout_marginTop="20dp"
        android:text="@string/trending_recipes"
        android:textSize="18sp" />

    <android.support.v7.widget.RecyclerView
        android:id="@+id/horizontaltrendingrecycleview"
        android:layout_width="match_parent"
        android:layout_height="240dp"
        android:layout_marginStart="15dp"
        android:orientation="horizontal"
        app:layout_behavior="@string/appbar_scrolling_view_behavior">
    </android.support.v7.widget.RecyclerView>

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="20dp"
        android:text="@string/all_recipes"
        android:textSize="18sp" />

    <android.support.v7.widget.RecyclerView
        android:id="@+id/recycleView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="20dp"
        app:layout_behavior="@string/appbar_scrolling_view_behavior">
    </android.support.v7.widget.RecyclerView>
    </LinearLayout>
</ScrollView>

我阅读了这篇文章“ Scolling with multiple RecyclerViews in Layout ”并以编程方式设置垂直回收视图的高度。像这样

LinearLayout.LayoutParams params = new     
 LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, 
 ViewGroup.LayoutParams.WRAP_CONTENT);
// calculate height of RecyclerView based on child count
params.height=1150;
// set height of RecyclerView
recyclerView.setLayoutParams(params);

但问题是我如何根据子计数计算 RecyclerView 的高度?

寿司

在您的in 中使用NestedScrollView代替ScrollView并使用以下行FragmentActivity

ViewCompat.setNestedScrollingEnabled(mYourRecycleView, false);

这将适用于您的所有 Android API 级别。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

如何从另一个活动的不同回收视图开始创建新的回收视图

当另一个滚动时如何隐藏回收视图

设置的意图,在OnCreate中回收视图去具体名单另一个特定活动(行)

检测水平过度滚动并在第一个细胞回收视图中显示删除选项

在顶部和底部的 2 个视图之间放置一个回收视图

滚动视图内的两个回收器视图

Android studio 如何将一个回收视图用于多个视图?

当一个表视图回收视图时,如何保持抽奖动画运行?

当在回收视图应用程序崩溃的同时选择两个项目,我怎么能解决这个问题?

在活动中添加两个片段,一个包含可滚动的列表视图,另一个包含静态内容

android在一个活动中两个滚动水平和垂直

在一个活动中显示两个活动

一个 django 项目两个应用程序,通用视图问题(类视图)

Android 显示光标在一个活动中导致两个不同的列表视图

Flutter:使两个列表视图可滚动为一个

一个滚动视图中包含两个UITableViews

两个按钮,一个活动

我可以在一个活动Android中使用2个以上的回收者视图吗

如何一起滚动两个列表视图

一个视图中的两个模型方向

一个视图有两个ViewModel

来自两个API的一个表视图

AngularJS:两个并行视图,一个URL

在一个视图中显示两个模型?

Android - 滚动视图内的回收视图

回收视图只显示 1 个元素

奇怪的两个同时滚动视图

Android:回收站视图没有滚动到最后一个位置

两个绝对div; 一个使滚动条出现;一个不