Alv*_*sli 4 android android-scrollview android-scroll android-recyclerview android-scrolling
您如何显示一侧(水平/垂直)非常大的项目列表,并允许它自由滚动/拖动 - 就像 Google 表格一样?
我试过使用 aNestedScrollView和 a RecyclerView,但一次只能向一个方向滚动,我需要它能够自由拖动(不需要捏/缩放功能,但如果可以做到,它是一个奖金)。
这是我尝试过的 GIF,它有效,但绝对不是我想要的。
这是布局文件:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<include
layout="@layout/include_toolbar"
android:id="@+id/toolbar" />
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.RecyclerView
android:id="@+id/recycler_biscroll"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</android.support.v4.widget.NestedScrollView>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
我终于得到了答案:使用自定义 LayoutManager 实现。
我删除了外部ScrollView,添加FixedGridLayoutManager到我的代码中,然后将其用作 RecyclerView 的布局管理器:
FixedGridLayoutManager layoutManager = new FixedGridLayoutManager();
layoutManager.setTotalColumnCount(adapter.getItemCount()); // This probably needs to update when item count is changed
recyclerView.setLayoutManager(layoutManager);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2504 次 |
| 最近记录: |