Implementing Simple CardView in android app with Android Studio .

In this post, you will learn simple implementation of Cardview in android studio .Cardview is a widget which was introduced un Android 7.0 . Based on its elevation, cardview gives a shadow effect the makes the app UI more beautiful and appealing. CardView is mainly considered as a container as it wraps for each item within a ListView or a RecyclerView . Here is a simple way to implement CardView in your application.

Add the following code to your xml file :

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#E5E5E5"
tools:context=".MainActivity">

<androidx.cardview.widget.CardView
android:id="@+id/cardView"
android:layout_width="350dp"
android:layout_height="600dp"
android:layout_centerHorizontal="true"
android:layout_marginStart="20dp"
android:layout_marginTop="20dp"
android:layout_marginBottom="40dp"
android:layout_marginEnd="20dp">

<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@drawable/nature"/>
</androidx.cardview.widget.CardView>

<Button
android:id="@+id/btn"
android:layout_width="150dp"
android:layout_height="60dp"
android:layout_below="@+id/cardView"
android:layout_centerHorizontal="true"
android:layout_marginBottom="15dp"
android:text="next"/>
</RelativeLayout>

Output :




To further enhance the appearance, various XML attributes can be implemented to the CardView.

XML attributes :









Comments

Popular posts from this blog

How to play Audio on Button Click in app | Android App Development | Java

Custom SeekBar in Android Studio .

How to implement simple Pie Chart in app | Android Studio | Java | Android App Development