Giter Site home page Giter Site logo

recyclerview-playground's Introduction

Android RecyclerView Examples

This repository contains examples for using the RecyclerView widget found in the Android Support Library.

Disclaimer

This repository contains sample code intended to demonstrate the capabilities of the RecyclerView layout manager APIs. It is not intended to be used as-is in applications as a library dependency, and will not be maintained as such. Bug fix contributions are welcome, but issues and feature requests will not be addressed.

Example Contents

The following bits can be found in the main sample application:

  • Implementation of LinearLayoutManager and GridLayoutManager for vertical and horizontal scrolling.
  • Custom ItemDecorations
  • InsetDecoration - Create an inset margin on all child views.
  • DividerDecoration - Create an inset margin and draw dividers below vertical child views.
  • GridDividerDecoration - Create an inset margin an draw dividers along grid lines
  • Custom LayoutManager
  • FixedGridLayoutManager - Similar to StaticGridLayoutManager, but with a controllable column count.

The following examples are incubating on the experimental branch (these mostly work, if you feel like living dangerously):

  • Custom LayoutManagers
  • StaticGridLayoutManager - 2D scrolling grid with variable column count based on data set. Window of visible (non-recycled) views is determined statically.
  • DynamicGridLayoutManager - 2D scrolling grid where window of visible views is determined dynamically. Results in fewer views in memory, but scrolling performance is questionable.

License

The code supplied here is covered under the MIT Open Source License:

Copyright (c) 2015 Wireless Designs, LLC

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

recyclerview-playground's People

Contributors

devunwired avatar joshallenit avatar lsjwzh avatar takahirom avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

recyclerview-playground's Issues

Request - more complex sample from larger streamed data source

Hi. First off, thanks for the great sample code!

One of the big things about RecyclerView is it's intelligence in viewing a subset of a large number of items. My request is that somebody extend this sample to show some approach to having a streamed data source. For example, if you had 1000 images loaded from a remote http server - it would show the first page of 20 and load more as you scroll down.

I know the add/remove kind of does this... but it tends to want to hold all of them in a single ArrayList in the sample. So if you scrolled up/down the page, the ArrayList would be fully populated with 1000 items. That wouldn't work very well for Android memory usage.

How would you approach making it "smart" to know there are 1000 total items for purposes of scrolling - but not have an ArrayList object that holds all 1000 after a full scroll up/down?

you could also use a SQL data source of 1000 items instead of a remote server. that might be easier to mock up. Thank you.

Unit Tests for improved test coverage

Hi

I do understand that this project is not actively maintained. However, I would like to understand that : Would it be helpful if I contribute some test cases to this sample application.

Thank you
Farid

dynamically added children

Unfortunately the FixedGridLayoutManager doesn't work correctly if I try to inflate dynamical children in onBindViewHolder.
I have an RecyclerView where every cell exists of another RecyclerView.
The height of the cells is always zero respectively the minimum height.

I already tried to replace the child-RecyclerView with a LinearLayout and add to this the children.
But this doesn't help.

unbenannt2

FixedTwoWayFragment snaps to origin on item click and view manipulation

In case of just one extra element (invisible) in a row and manipulating sub views on click causes it to snap to the first element. Here is the video showing it and here is the source code that is used the video

I hide one the row item sub views(home score textview). If I do not hide the textview and only change its value it works fine. Also if there are more than one (1) elements off the screen it works fine.

I went through the source code of FixedGridLayoutManager and it turns out this code is responsible for snapping.

if (getChildCount() == 0) { //First or empty layout
    //Reset the visible and scroll positions
    mFirstVisiblePosition = 0;
    childLeft = getPaddingLeft();
    childTop = getPaddingTop();
} else if (!state.isPreLayout()
        && getVisibleChildCount() >= state.getItemCount()) {
    //Data set is too small to scroll fully, just reset position
    mFirstVisiblePosition = 0;
    childLeft = getPaddingLeft();
    childTop = getPaddingTop();
} 

It goes into the else if block and resets position.

Also while calculating mVisibleColumnCount and mVisibleRowCount you add 1, any particular reason for that?

mVisibleColumnCount = (getHorizontalSpace() / mDecoratedChildWidth) + 1;
mVisibleRowCount = (getVerticalSpace()/ mDecoratedChildHeight) + 1;

Suggest Apache 2.0 license

Hello. Thank you for your work!

I suggest you add Apache 2.0 license (dual license) so the code can be mixed easier with Android samples that Google provides. As it is now, being MIT license, often people would be mixing code from different sources and even if they are "compatible" - they are distinctive... so it becomes hybrid code. Thank you for the consideration.

Padding doubled in FixedTwoWayList on first layout

Hi Dave,
there is a problem when adding a padding to the RecyclerView and with the FixedGridLayoutManager.

Steps to reproduce:
Add a padding to the Recyclerview in fragment_recycler.xml eg.:

android:padding="30dp"
android:clipToPadding="false"

Start the app, select "Fixed Two-Way List" and then "Large Grid"
The padding is now double the size is should be.
When you start to scroll it jumps back to the correct padding.

I was able to fix it by changing line 263 in FixedGridLayoutManager.java to:
fillGrid(DIRECTION_NONE, 0, 0, recycler, state, removedCache);
but I am not sure about any other effects this might have.

Best regards,
Stephan

Implement fixed headers for rows and columns

Hi, first thanks for this playground around RecyclerView adapters. This and the talk are extremely useful resources.

I was thinking on modifying the FixedGridLayoutManager to support fixed headers for both columns and rows (would look something like this: https://github.com/InQBarna/TableFixHeaders)
I wanted to know if you would have any advice on how to actually implement this or do you have any recommendation for it?

Thanks!

Refreshing data in RecyclerView and keeping its scroll position?

// Save state
private Parcelable recyclerViewState;
recyclerViewState = recyclerView.getLayoutManager().onSaveInstanceState();

// Restore state
recyclerView.getLayoutManager().onRestoreInstanceState(recyclerViewState);

FixedGridLayoutManager onSaveInstanceState and onRestoreInstanceState does not implement

A question about Filterable

Has handling of filtering of the items using RecyclerView changed over the normal way of ListView ?
How should it be handled now?

Pull to Refresh conflict

I've see some conflict with Pull to Refresh when user scroll to top. If the project has used LinearLayoutManager or GridLayoutManager, this doesn't happens.

In custom LayoutManager (extends RecyclerView.LayoutManager) RecyclerView.getChildViewHolderInt NullPointerException issue

Hi!
After trying similar to this (simplify version):

@Override
public void onLayoutChildren(RecyclerView.Recycler recycler, RecyclerView.State state) {
     ....
     addView(new TextView(mRecyclerView.getContext()))
}

I have an exception:

java.lang.NullPointerException
    at android.support.v7.widget.RecyclerView.getChildViewHolderInt(RecyclerView.java:2497)
    at android.support.v7.widget.RecyclerView$LayoutManager.addViewInt(RecyclerView.java:4807)
    at android.support.v7.widget.RecyclerView$LayoutManager.addView(RecyclerView.java:4803)
    at android.support.v7.widget.RecyclerView$LayoutManager.addView(RecyclerView.java:4791)

I can't add to RecyclerView child view without ViewHolder?

Marking views recyclable algorithm when in fling state

Dear Dear Dave Smith:

Great job!

But could you please help me about some cofusions?

Currently I dive into your code of the FixedGirdLayoutManager, it confused me.

To make it simple, suppose it only scroll vertically.

When slowly scrolling,RecyclerView will tell the manager to do something by : scrollVerticallyBy()

and then detach all the views then calculate the visible rows and columns then
find the right child views that are still in the visible area. If no view is
ready for the slot, then create a new one.

This is understandable.

But with a fling gesture, it seems that the the old and
new created child views are positioned in a quite large negtive Pos by:

old views:
1.offsetChildrenVertical(delta); in scrollVerticallyBy() of fixedGridLayoutManager

new views:
2.layoutDecorated(); in fillGrid() of fixedGridLayoutManager

I have log them out,Plz have a look at the log :

layoutDecorated.png:
layoutdecorated

offsetChildrenVertical.png:
offsetchildrenvertical

This confused me for a long time , I cannot figure it out:
When fling the recyclerview vertically bottom up;

  1. Why we need to position the child view from a large negtive position in the y-axis , for exeample: -1766
    while my recyclerView height is : 1293. Isn't the position -1766 deem bo be invisible to my recyclerview? Then why have to attach view from here?
  2. I noticed that when scrolling down, if the bottom of the fist view in the recyclerView is negetive,
    you will increase the mFirstVisiblePosition by 1 to mark that view is recyclable. This marking recyclable algorithm is a little hard to understand. Why only mark the top row of child views recyclable. How dose it work?

Please, I beg for your answers.
I have been confusing by these questions for a long time.

FixedGridLayoutManager vertical scroll issue

Hi All,
I was playing around FixedGridLayoutManager and tried to have a RecyclerView with FixedGridLayoutManager as an item of RecyclerView with LinearLayoutManager (Vertical).

The problem is now the RecyclerView with FixedGridLayoutManager does not scroll vertically.
ViewHolder for parent RecyclerView with LinearLayoutManager is as follows -

public static class VerticalItemHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
private SimpleTVAdapter mAdapter;
private RecyclerView recyclerView;
private TextView sectionTitle;

    public VerticalItemHolder(View itemView, SimpleTVAdapter adapter) {
        super(itemView);
        itemView.setOnClickListener(this);

        mAdapter = adapter;
        recyclerView = (RecyclerView) itemView.findViewById(R.id.tv_list);
        sectionTitle = (TextView) itemView.findViewById(R.id.sectionTitle);
    }

    @Override
    public void onClick(View v) {
        mAdapter.onItemHolderClick(this);
    }

    public void setSectionTitle(CharSequence text) {
        this.sectionTitle.setText(text);
    }

    public void setUpRecyclerViewItem(FixedGridLayoutManager manager,
                                      SimpleAdapter mAdapter, DividerDecoration dividerDecoration) {
        manager.setTotalColumnCount(10);
        recyclerView.setLayoutManager(manager);
        recyclerView.addItemDecoration(dividerDecoration);
        mAdapter.setItemCount(60);
        recyclerView.setAdapter(mAdapter);

    }
}

Can anyone point me in right direction how to achieve RecyclerView (FixedGrid) as an item inside another RecyclerView (Linear Vertical)?

Thank you.

Not working when enclosed inside a NestedScrollView

For my use case, I had to include a RecylerView a NestedScrollVIew. Once I do that, the layout manager does not work anymore. I thought it would be a height issue so I modified the FixedGridLayoutManager to include setAutoMeasureEnabled(true). That caused the content to show up but the scrolling would not happen.

I also tried enabling and disabling NestedScrolling on the RecyclerView.

Sample:


<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fillViewport="true">

    <android.support.v7.widget.RecyclerView xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/rvFanClubs"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:clipChildren="false"
        android:clipToPadding="false"
        android:paddingLeft="12dp"
        android:paddingRight="12dp" />

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

RTL Layout

Hi, how can I add support for RTL layout?
you've not implemented setReverseLayout

Issue on fling with curved motion (y and x axis simultaneous movement)

In FixedGridLayoutManager when scrolling with a fling motion with a slight curve, triggering an unintentional scroll on both axis (try a a fling curve motion starting from lower left corner ending to upper right corner), I can see the grid children filling the view with some delay (I see the white background with the dividers scrolling and then the grid items fill the view). If I try with fast continuous flings I can stop the grid with some grid item positions not yet filled with the appropriate views, seeing only the white backround. If I later move the grid it gets filled as normal.
I think the problem is the fast scrolling movement in both axis. Can I somehow disable the movement to the other direction when flinging? I don't care much for diagonal scrolling.
I have been using your example app, with 10 columns and a lot of rows (1500).

Stacked cards LinearLayout

Hey, Im sorry to bother you here :P First let me thank you about this demo app, its actually the only one that truly explain how to build a layoutmanager. I have a requirement in my app in which i have to develop a scrolling behavior in which the first card stays fixed in the layout, and the other cards will overlap the first card and disappear after.

It is like a stack of cards, except only the first card will stack. I find it hard to manage the different card overlapp offsets, and i'm strugling really hard with it.

Do you have any sample demo in which such behavior (or kind of) is present? Or can you give me any tips about how to accomplish such a thing.

thanks in advanced,
John

FixedGridLayoutManager variable column width

Hello and thank you for these great examples.

With FixedGridLayoutManager is it possible to have the columns with different widths? I noticed that all column widths are determined by the size of the first cell. At the time of setTotalColumnCount() I know what the widths will be.

Multi type item wrong size

Good day, I try to use FixedGridLayoutManager class in my project, and when I add to recyclerView different items, there are have same height and wight, like in first shown.
I think, that problem in this part:

/*
             * We make some assumptions in this code based on every child
             * view being the same size (i.e. a uniform grid). This allows
             * us to compute the following values up front because they
             * won't change.
             */
            mDecoratedChildWidth = getDecoratedMeasuredWidth(scrap);
            mDecoratedChildHeight = getDecoratedMeasuredHeight(scrap);

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.