ScrollablePanel Android Library

repository·master·Indexed 24 days ago

https://github.com/kelin-hong/scrollablepanel

An Android library providing a two-dimensional scrolling view that pins the first row and first column, functioning similarly to a 2D RecyclerView with fixed headers and sidebars. It utilizes a PanelAdapter to manage data dimensions and binding logic using row and column coordinates.

Tokens
1.2K
Snippets
4
Records
5
Agent score
35%

What's inside ScrollablePanel

  1. What is ScrollablePanel

    master
    ScrollablePanel is a flexible Android view designed to provide a limited rectangular window into a large two-dimensional data set. It functions similarly to a two-dimensional RecyclerView, but with a key distinction: it pins the itemView of the first row and the first column in their original locations, acting like a panel with fixed headers/sidebars.
  2. Initialize ScrollablePanel in XML

    master

    Include the ScrollablePanel in your layout XML file. Ensure you use the full package name for the component:

    <com.kelin.scrollablepanel.library.ScrollablePanel
            android:id="@+id/scrollable_panel"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />
  3. Set the adapter on ScrollablePanel

    master

    Once your PanelAdapter is implemented, attach it to the ScrollablePanel instance using setPanelAdapter() within your Activity or Fragment:

    @Override
    protected void onCreate(Bundle savedInstanceState) {
       ...
       ...
       TestPanelAdapter testPanelAdapter = new TestPanelAdapter();
       ScrollablePanel scrollablePanel = (ScrollablePanel) findViewById(R.id.scrollable_panel);
       scrollablePanel.setPanelAdapter(testPanelAdapter);
       ...
       ...
    }
  4. Implement PanelAdapter

    master

    To display data, you must create a custom adapter by extending PanelAdapter. You are required to override several methods to define your data dimensions and binding logic. This is similar to a standard RecyclerView.Adapter but uses row and column coordinates instead of a single position.

    public class TestPanelAdapter extends PanelAdapter {
        private List<List<String>> data;
    
        @Override
        public int getRowCount() {
            return data.size();
        }
    
        @Override
        public int getColumnCount() {
            return data.get(0).size();
        }
    
        @Override
        public int getItemViewType(int row, int column) {
            return super.getItemViewType(row, column);
        }
    
        @Override
        public void onBindViewHolder(RecyclerView.ViewHolder holder, int row, int column) {
            String title = data.get(row).get(column);
            TitleViewHolder titleViewHolder = (TitleViewHolder) holder;
            titleViewHolder.titleTextView.setText(title);
        }
    
        @Override
        public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
            return new TestPanelAdapter.TitleViewHolder(LayoutInflater.from(parent.getContext())
                    .inflate(R.layout.listitem_title, parent, false));
        }
    
        private static class TitleViewHolder extends RecyclerView.ViewHolder {
            public TextView titleTextView;
    
            public TitleViewHolder(View view) {
                super(view);
                this.titleTextView = (TextView) view.findViewById(R.id.title);
            }
        }
    }