Online Tutorials & Training Materials | STechies.com
Register Login

CardView Example in Android Studio

|| || 0

CardView Example in Android Studio
Stechies

How to Create CardView Layout in Android Studio?

This tutorial explains step by step how to create CardView layout example via Android Studio.

Please follow the steps below in order create CardView layout in Android Studio without Programming:

1.Go to the design tab. Remove the “Hello world” text from the screen.

2.Go to the text tab and change the relative layout to scroll view.

3.Go to the design tab. Select Linear layout (vertical) and drag it to the window.

4.Go to the text tab. Go to Gradle scripts > Build.Gradle (Module app).

5.Add a compile line.

"compile 'com.android.support:cardview-v7:24.2.2'."

And then click on Sync now.

6.Go to activity.xml and  Add a CardView.

7.Add relative layout and match parent.

8.Add a textView.

android: text="something"

9.Go to design tab. You can now view the CardView.

10.Next add an ImageView from the text tab.

11.You can now notice the image in the widget.

Adding multiple CardViews

12.Copy and paste the cardview as many times as you want it. Check the image on the left hand side.

Adding OnClickListener

13.Go to text tab. Select the first cardView.

14.Add an id for it. Do the same for the other cardviews.

15.Click on MainActivity.java. Type CardView cd1, cd2, cd3.

16.Mention the CardViews.

17.Next add the OnClickListener for the cardviews.

18.Check the live view window. The listener will shows which card view you selected.



Related Articles