Monday, 27 July 2015

How to Create Card View in Android


Step 1. Create New Project in you Android Studio named “CardViewDemo”
Step 2. Add “com.android.support:cardview-v7:21.0.+” compile dependencies to you project .
Step 3. Add below code to your activity_main

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
android:gravity="center">
<android.support.v7.widget.CardView
xmlns:card_view="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/cardView1"
card_view:cardCornerRadius="4dp"
android:layout_margin="5dp"
android:gravity="center"
>
<TextView
android:layout_gravity="center"
android:text="CardView"
android:textSize="40sp"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</android.support.v7.widget.CardView>
</RelativeLayout>

Run your code and you can see TextView inside Card View.
For any query comment here.
Thank you

No comments:

Post a Comment