Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use RecyclerView and CardView

I don't have much experience in android development and try to implement RecyclerView in my application. The version of android studio does not have Android L neither there is option to install. Everytime it says android.support.widget.v7.RecyclerView in not used and disabled it from import packages. I give refrences in layout file also in Gradle.build but my problem is still there anyone help please?

like image 551
Awdi Avatar asked Jul 13 '15 06:07

Awdi


People also ask

What is RecyclerView and CardView?

CardView: CardView is an extended version of Framelayout which can be used to show items inside the card format. With the help of CardView, we can add radius and elevation to our items of RecyclerView.

When should I use CardView?

CardView is a new widget in Android that can be used to display any sort of data by providing a rounded corner layout along with a specific elevation. CardView is the view that can display views on top of each other. The main usage of CardView is that it helps to give a rich feel and look to the UI design.

What is Androidx CardView?

↳ androidx.cardview.widget.CardView. A FrameLayout with a rounded corner background and shadow. CardView uses elevation property on Lollipop for shadows and falls back to a custom emulated shadow implementation on older platforms.


1 Answers

Follow this line

  • CardView and RecyclerView in Material Design

http://icetea09.com/blog/2014/12/19/android-cardview-and-recyclerview-in-material-design/

add these into the dependencies:

    compile 'com.android.support:cardview-v7:22.2.0'
    compile 'com.android.support:recyclerview-v7:22.2.0'

and update the gradle in module's build.gradle

  • Example for each one:

CardView

<android.support.v7.widget.CardView
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    card_view:contentPadding="16dp"
    card_view:cardElevation="2dp"
    card_view:cardCornerRadius="5dp">

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

        <TextView
            style="@style/Base.TextAppearance.AppCompat.Headline"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="Title" />

        <TextView
            style="@style/Base.TextAppearance.AppCompat.Body1"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="Content here" />

    </LinearLayout>

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

RecyclerView:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <android.support.v7.widget.RecyclerView
        android:id="@+id/recycler_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>

</LinearLayout>
like image 90
Abhishek Avatar answered Sep 19 '22 19:09

Abhishek