[Android] CardView in Android

The day before her had called us and instruct you to use RecyclerView in Android. This article will continue to guide you using CardView – View used a combination with RecyclerView or ListView.

What is CardView

CardView allow you to display content in a more prominent, shadow effect, bo beautiful corner. And especially when combined with RecyclerView. If you have used android 4.0 or more often see the app has a list like this.

cardview in android

Use CardView in Eclipse

For those you do not use Android weak machine but must use Eclipse Studio

Step 1: Import CardView
Chọn menu File -> Import -> Existing Android code into workspace –> Browse (Go to sdk/extras/android/support/v7/cardview) –> Click ok –> Click Finish

Step 2: The definition is CardView 1 library.
Right click on the project Cardview –> Properties –> Android –> Enable isLibrary (tick the checkbox) –> Apply –> ok

Step 3: Use cardview in the main Project
Right click on your project –> Properties –> Android –> Add –> cardview –> apply –> ok

That's it.

Use CardView in Android Studio

Add the following to the file build.grade

compile 'com.android.support:cardview-v7:21.0.+'

That's it…

Code generated in xml CardView

Suppose we do more examples RecyclerView in Android as the day before and now we give each item is 1 cardview. (as the first photo post)

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

    <LinearLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:card_view="http://schemas.android.com/apk/res-auto"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:gravity="center_vertical"
        android:orientation="horizontal" >

        <TextView
            android:id="@+id/tv_name"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_margin="8dp"
            android:layout_weight="1" />

        <ImageButton
            android:id="@+id/btn_delete"
            android:layout_width="32dp"
            android:layout_height="32dp"
            android:src="@drawable/ic_delete" />
    </LinearLayout>

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

In which you noticed card_view:cardCornerRadius =”4dp” Help us make the items have rounded corners 4dp.

Download the complete code RecyclerView_with_CardView