4

How do you display a list of item that is very large on one side (either horizontally / vertically), and allow it to be freely scrolled / dragged - like Google Sheets?

I've tried using a NestedScrollView with a RecyclerView, but you can only scroll in one direction at a time, and I need it to be able to be freely dragged around (no pinch / zoom functionality is required, but if it can be done it's a bonus).

Here's a GIF of what I've tried, it works but it's definitely not what I'm looking for.

enter image description here

This is the layout file:

<?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>
Alvin Rusli
  • 830
  • 1
  • 9
  • 19
  • I think [this](https://stackoverflow.com/a/36421383/4439129) answer will solve your problem. – Lester L. Jan 11 '18 at 08:23
  • @LesterL. I've already tried both ScrollView & NestedScrollView, it works but i cannot freely drag the layout 'diagonally'. – Alvin Rusli Jan 11 '18 at 08:55

2 Answers2

5

I finally got an answer: Use a custom LayoutManager implementation.

I removed the outer ScrollView, added FixedGridLayoutManager on my code, then used it as the RecyclerView's layout manager:

FixedGridLayoutManager layoutManager = new FixedGridLayoutManager();
layoutManager.setTotalColumnCount(adapter.getItemCount()); // This probably needs to update when item count is changed
recyclerView.setLayoutManager(layoutManager);
Alvin Rusli
  • 830
  • 1
  • 9
  • 19
0

Have you tried putting the recycler view inside a scroll view?