CardView的具體,修飾控件的作用,增加圓角,陰影效果


CardView是在安卓5.0提出的卡片式控件。Cardview繼承自FrameLayout,所以子控件布局規則和FrameLayout的一樣,首先介紹一下它的配置。 

在gradle文件下添加依賴庫:

compile 'com.android.support:cardview-v7:22.2.1'

基本屬性: 
app:cardBackgroundColor這是設置背景顏色 
app:cardCornerRadius這是設置圓角大小 
app:cardElevation這是設置z軸的陰影 
app:cardMaxElevation這是設置z軸的最大高度值 
app:cardUseCompatPadding是否使用CompatPadding  一般是為了兼容設備,保持一樣的外觀,所以為了保持內邊距的計算方式一樣就使用吧 
app:cardPreventCornerOverlap是否使用PreventCornerOverlap 這個屬性為了防止內容和邊角的重疊
app:contentPadding 設置內容的padding 
app:contentPaddingLeft 設置內容的左padding 
app:contentPaddingTop 設置內容的上padding 
app:contentPaddingRight 設置內容的右padding 
app:contentPaddingBottom 設置內容的底padding

CardView的使用:

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginBottom="10dp"
    android:background="@color/gray">

    <android.support.v7.widget.CardView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginLeft="10dp"
        android:layout_marginRight="10dp"
        app:cardBackgroundColor="@color/blue"
        app:cardCornerRadius="16dp"
        app:cardElevation="16dp">

    </android.support.v7.widget.CardView>
</FrameLayout>

 寫完CardView的布局之后,需要在清單文件的applicationo中開啟硬件加速

android:hardwareAccelerated="true"

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM