Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Recycler View - Android Alliance March 2016

Recycler View - Android Alliance March 2016

An intro to RecyclerView

Yash Prabhu

March 30, 2016
Tweet

More Decks by Yash Prabhu

Other Decks in Technology

Transcript

  1. RecyclerView
    Yash Prabhu
    @yashvprabhu
    github.com/yprabhu
    yprabhu.com
    dramafever.com

    View full-size slide

  2. What is RecyclerView?

    View full-size slide

  3. What does it look like?

    View full-size slide

  4. Under the hood
    Recycler View
    Layout Manager
    Adapter Dataset
    Item Animator

    View full-size slide

  5. Show me the code!
    compile 'com.android.support:appcompat-v7:23.1.1'
    compile 'com.android.support:recyclerview-v7:23.1.1'

    View full-size slide

  6. Add RecyclerView to your layout
    android:id="@+id/my_recycler_view"
    android:scrollbars="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent"/>

    View full-size slide

  7. View Item

    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="300dp"
    android:layout_height="300dp"
    android:layout_margin="@dimen/spacing">
    android:id="@+id/image"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:scaleType="centerCrop"
    tools:src="@mipmap/ic_launcher" />
    android:id="@+id/text"
    android:layout_width="match_parent"
    android:layout_height="60dp"
    android:layout_gravity="bottom"
    android:textColor="@android:color/white"
    android:gravity="center"
    android:background="#80222222"
    android:padding="@dimen/spacing"
    tools:text

    View full-size slide

  8. Show me the code!
    setContentView(R.layout.recycler_layout);
    recyclerView = (RecyclerView) findViewById(R.id.my_recycler_view);
    recyclerView.setHasFixedSize(true);
    adapter = new RecyclerAdapter(items, R.layout.grid_view_item);
    recyclerView.setAdapter(adapter);
    layoutManager = new GridLayoutManager(this, spanCount);
    recyclerView.setLayoutManager(layoutManager);
    recyclerView.setItemAnimator(new DefaultItemAnimator());

    View full-size slide

  9. Demo
    RecyclerViewExample

    View full-size slide

  10. When should I use a
    RecyclerView?

    View full-size slide

  11. RecyclerView
    Yash Prabhu
    @yashvprabhu
    github.com/yprabhu
    yprabhu.com
    dramafever.com

    View full-size slide