【问题标题】:scrollbar not working on touch android滚动条在触摸android上不起作用
【发布时间】:2025-12-23 09:40:10
【问题描述】:

我在回收站视图上启用了滚动条,但我无法使用该滚动条进行滚动。

<android.support.v7.widget.RecyclerView
        android:id="@+id/my_recycler_view"
        android:scrollbars="vertical"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="4"
        android:scrollbarSize="50dp"
        />

类似的东西。

但仅此而已,我无法按住滚动条并向下/向上滚动。

如何让它可滚动?就像我可以触摸并向下拖动一样。

更新:

已被标记为重复的问题使用列表视图。 我正在使用recyclerview,但我没有看到here 提供的这两个属性。

【问题讨论】:

标签: android


【解决方案1】:

如果您在 RV 上使用 CoordinatorLayout 和 Toolbar,请尝试将 app:layout_behavior="@string/appbar_scrolling_view_behavior" 属性添加到 RecyclerView。

【讨论】:

    【解决方案2】:

    我建议您只使用 RecyclerView 创建一个新的布局文件: vertical_recycler_view.xml

    <android.support.v7.widget.RecyclerView
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/my_recycler_view"
        android:scrollbars="vertical"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="4"
        android:scrollbarSize="50dp"/>
    

    现在你可以在任何你想要的地方膨胀和添加带有滚动条的 RecyclerView: MyCustomViewGroup.java

    public class MyCustomViewGroup extends FrameLayout
    {
        public MyCustomViewGroup(Context context)
        {
            super(context);
    
            RecyclerView verticalRecyclerView = (RecyclerView) LayoutInflater.from(context).inflate(R.layout.vertical_recycler_view, null);
            verticalRecyclerView.setLayoutManager(new LinearLayoutManager(context, LinearLayoutManager.VERTICAL, false));
            addView(verticalRecyclerView);
        }
    }
    

    【讨论】: