【问题标题】:RecyclerView inside NestedScrollView : make horizontal scroll easier to doNestedScrollView 内的 RecyclerView :使水平滚动更容易
【发布时间】:2016-04-08 06:07:29
【问题描述】:

我正在开发一个 Android 应用程序,我有一个垂直的 NestedScrollView,它占据了我所有的屏幕,并在多个水平 RecyclerView 内。可以,但是横向滚动真的很难实现。

我的意思是,当我水平滚动时,手势被 NestedScrollView 捕获,并且视图向上/向下移动。我需要集中注意力并做一个真正的水平移动来滚动 RecyclerView,它正在扼杀 UX...

这是我的 NestedScrollView :

<android.support.v4.widget.NestedScrollView
    android:id="@+id/scrollView"
    android:scrollbars="none"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_marginTop="5dp"
    android:layout_marginEnd="5dp"
    android:layout_marginRight="5dp"
    android:layout_marginLeft="5dp"
    android:layout_marginStart="5dp">

    <LinearLayout
        android:layout_height="wrap_content"
        android:layout_width="match_parent"
        android:id="@+id/scrollLayout"
        android:orientation="vertical" />

</android.support.v4.widget.NestedScrollView>

我正在以编程方式膨胀 RecyclerView,因为数字是在网络数据中定义的,这里是膨胀的布局:

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

    <TextView
        android:textSize="@dimen/secondary_text_size"
        android:textAllCaps="true"
        android:layout_marginBottom="5dp"
        android:layout_marginTop="5dp"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

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

</LinearLayout>

以及我如何在 Java 中设置 RecyclerView :

LayoutInflater inflater = LayoutInflater.from(context);
LinearLayout layout = (LinearLayout) inflater.inflate(R.layout.recycler_view_layout, null, false);

RecyclerView recyclerView = (RecyclerView) layout.findViewById(R.id.recyclerView);
LinearLayoutManager layoutManager = new LinearLayoutManager(context, LinearLayoutManager.HORIZONTAL, false);

recyclerView.setHasFixedSize(false);
recyclerView.setLayoutManager(layoutManager);
recyclerView.setAdapter(this);
recyclerView.setItemAnimator(new DefaultItemAnimator());
recyclerView.setNestedScrollingEnabled(false);

我尝试更改“速度”NestedScrollView,但找不到好的建议/帖子,也许我找不到好的建议。有人可以帮忙吗?

【问题讨论】:

    标签: android android-recyclerview nestedscrollview


    【解决方案1】:

    希望你觉得它有用,因为我认为你需要实现这些库之一(在 GitHub 上你会找到更多):


    如果你想使用标准的 Android 库,RecyclerView 如果你想水平滚动可能会很有用

    要证明它有水平滚动支持,看一下:

    公共布尔值 canScrollHorizo​​ntally ()

    查询当前是否支持水平滚动。默认 实现返回 false。

    返回如果此 LayoutManager 可以水平滚动当前内容则为真

    public int computeHorizo​​ntalScrollExtent(RecyclerView.State 状态)

    如果要支持滚动条,请覆盖此方法。

    阅读 computeHorizo​​ntalScrollExtent() 了解详情。

    默认实现返回 0。

    发件人:https://developer.android.com/reference/android/support/v7/widget/RecyclerView.LayoutManager.html

    还要检查 RecyclerView 的子类,称为 HorizontalGridView

    希望对您有所帮助。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-01-16
      • 1970-01-01
      • 2018-07-20
      • 2020-06-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多