Recycler View - Android Alliance March 2016

Recycler View - Android Alliance March 2016

An intro to RecyclerView

00bc3e6ec35c62fabef044e492070c29?s=128

Yash Prabhu

March 30, 2016
Tweet

Transcript

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

  2. What is RecyclerView?

  3. What does it look like?

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

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

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

  7. View Item <?xml version="1.0" encoding="utf-8"?> <FrameLayout xmlns:android="http://schemas.android. com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="300dp"

    android:layout_height="300dp" android:layout_margin="@dimen/spacing"> <ImageView android:id="@+id/image" android:layout_width="match_parent" android:layout_height="match_parent" android:scaleType="centerCrop" tools:src="@mipmap/ic_launcher" /> <TextView 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
  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());
  9. Demo RecyclerViewExample

  10. When should I use a RecyclerView?

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