【Android - MD】之CardView的使用

來源:互聯網
上載者:User

標籤:div   cardview   iss   tree   eve   nbsp   技術分享   ref   技術   

CardView是Android 5.0新特性——Material Design中的一個布局控制項,可以通過屬性設定顯示一個圓角的類似卡片的視圖。

 

1、CardView的屬性:

app:cardCornerRadius:CardView的圓角大小        app:cardElevation:CardView的陰影大小        app:cardMaxElevation:CardView最大陰影大小        app:cardPreventCornerOverlap:CardView中的內容是否和圓角重疊,true為不重疊        註:如果CardView中有一張填充布局的圖片,則如果不設定cardPreventCornerOverlap為true的話,圖片的四個角            會延伸到CardView的圓角之外

 

2、示範代碼:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"    xmlns:app="http://schemas.android.com/apk/res-auto"    android:id="@+id/activity_main"    android:layout_width="match_parent"    android:layout_height="match_parent">    <android.support.v7.widget.CardView        android:layout_width="match_parent"        android:layout_height="200.0dip"        android:layout_margin="20.0dip"        app:cardCornerRadius="10.0dip"        app:cardElevation="5.0dip"        app:cardMaxElevation="15.0dip"        app:cardPreventCornerOverlap="true">        <ImageView            android:layout_width="match_parent"            android:layout_height="match_parent"            android:contentDescription="@string/app_name"            android:scaleType="centerCrop"            android:src="@mipmap/bg" />        <TextView            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:layout_gravity="center"            android:text="THIS IS A CARDVIEW"            android:textColor="#FFFFFFFF"            android:textSize="24.0sp"            android:textStyle="bold" />    </android.support.v7.widget.CardView></RelativeLayout>

 

運行結果:

 

以上就是對CardView簡單使用方法的介紹,下面貼出碼雲上的源碼,供大家參考。

DEMO地址

【Android - MD】之CardView的使用

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.