Android Basics – Using Layout Manager with Recycler View to arrange Views

The advantage of using a RecyclerView over ListView is that you get the option to arrange how the views display.

You have the option to display views in a linear list, a grid or a staggered grid.

To use the LayoutManager you need to add the following code

LinearLayoutManager manager = new LinearLayoutManager(this);
recyclerView.setLayoutManager(manager);

Source code is available here

Android Basics – Learn how to create a Card View

The last Article introduced you to Material Design basics. In this Article you will learn how to create a Card View.

Steps to add a CardView

  • Add support libraries – com.android.support.cardview and recyclerview
  • Create a layout xml file for the card view.
  • Refer to the below code snippet
<?xml version="1.0" encoding="utf-8"?>

<android.support.v7.widget.CardView
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:card_view="http://schemas.android.com/apk/res-auto"
    android:id="@+id/card_view"
    android:layout_width="match_parent"
    android:layout_height="200dp"
    android:layout_margin="5dp"
    card_view:cardCornerRadius="4dp">

    <LinearLayout android:layout_width="match_parent"
                  android:layout_height="fill_parent"
                  android:orientation="vertical">

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Hello Card View"
            android:layout_margin="5dp"/>

    </LinearLayout>

</android.support.v7.widget.CardView>

Source Code is available here