Android 5.0 CardView App

Source: Internet
Author: User


CardView belongs to the new widget inside the support V7. Extended to Framelayout,

The UI display mainly includes

1. Border rounded corners

2 A Shadow Shadow

Used to highlight personality, such as exhibitions, albums, etc.


Main layout

<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 "Android: paddingleft= "@dimen/activity_horizontal_margin" android:paddingright= "@dimen/activity_horizontal_margin" Android :p addingtop= "@dimen/activity_vertical_margin" android:paddingbottom= "@dimen/activity_vertical_margin" tools: context= "com.example.gaofeng.recyclerviewdemo.CardViewActivity" xmlns:card_view= "http://schemas.android.com/apk /res-auto "> <android.support.v7.widget.cardview xmlns:card_view=" Http://schemas.android.com/apk/res-au To "android:id=" @+id/card_view "android:layout_width=" match_parent "android:layout_height=" Wrap_conte NT "card_view:cardbackgroundcolor=" @android: Color/white "android:layout_marginleft=" @dimen/activity_horizont Al_margin "android:layout_marginright=" @dimen/activity_horizontal_marGin "android:layout_margintop=" 5DP "android:layout_marginbottom=" 5DP "card_view:cardcornerradius=" 10d P "card_view:cardelevation=" 24DP "> <relativelayout android:layout_width=" match_parent "Andro id:layout_height= "Match_parent" android:paddingbottom= "@dimen/activity_vertical_margin" android:paddingTop= " @dimen/activity_vertical_margin "> <imageview android:id=" @+id/img "Android:layout_widt H= "Match_parent" android:layout_height= "wrap_content" android:src= "@drawable/cat0" Androi D:layout_centerhorizontal= "true" android:scaletype= "Fitcenter"/> <textview android:id=            "@+id/text_desc" android:layout_width= "wrap_content" android:layout_height= "Wrap_content"  android:layout_below= "@+id/img" android:layout_centerhorizontal= "true" android:text= "This is a card View "Android:paddingleft= "@dimen/activity_horizontal_margin" android:paddingright= "@dimen/activity_horizontal_margin"/&gt    ; </RelativeLayout> </android.support.v7.widget.CardView> <seekbar android:layout_below= "@+id/card_ View "android:id=" @+id/seek1 "android:layout_margintop=" 10DP "android:layout_width=" 150DP "and roid:layout_height= "30DP"/> <seekbar android:layout_below= "@+id/seek1" android:id= "@+id/see        K2 "android:layout_margintop=" 10DP "android:layout_width=" 150DP "android:layout_height=" 30DP " /></relativelayout>

A few important attributes:

card_view:cardcornerradius= radius of "10DP" fillet
Card_view:cardelevation= "24DP" Shadow Shadow


Seekbar is used to test these 2 values.


Package Com.example.gaofeng.recyclerviewdemo;import Android.support.v7.app.actionbaractivity;import Android.os.bundle;import Android.support.v7.widget.cardview;import Android.view.menu;import Android.view.MenuItem    Import Android.widget.seekbar;public class Cardviewactivity extends Actionbaractivity {CardView cardview = null;        @Override protected void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate);        Setcontentview (R.layout.activity_card_view);        CardView = (CardView) Findviewbyid (R.id.card_view);        SeekBar seek1 = (SeekBar) Findviewbyid (R.ID.SEEK1);        SeekBar Seek2 = (SeekBar) Findviewbyid (R.ID.SEEK2); Seek1.setonseekbarchangelistener (New Seekbar.onseekbarchangelistener () {@Override public void Onpro Gresschanged (SeekBar SeekBar, int i, Boolean b) {if (b) {cardview.setcardelevation (i); /shadow}} @Override Publicvoid Onstarttrackingtouch (SeekBar SeekBar) {} @Override public void Onstoptrackingtouch (        SeekBar SeekBar) {}}); Seek2.setonseekbarchangelistener (New Seekbar.onseekbarchangelistener () {@Override public void Onpro Gresschanged (SeekBar SeekBar, int i, Boolean b) {if (b) {Cardview.setradius (i);//Fillet size Set            @Override public void Onstarttrackingtouch (SeekBar SeekBar) {    } @Override public void Onstoptrackingtouch (SeekBar SeekBar) {}}); }


Some 5.0 of the simulators do not see the Shadow build a Nexus 1080 simulator can see.



Drag Seekbar large dots have obvious shadows and rounded corners.


Build.gradle Join Dependency


dependencies {    compile ' com.android.support:appcompat-v7:22.0.0 '    compile Filetree (dir: ' Libs ', include: [' * '). Jar '])    compile ' com.android.support:recyclerview-v7:21.0.+ '    compile ' com.android.support:cardview-v7 : 21.0.+ '}






Android 5.0 CardView App

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.