android CardView常用屬性

                        

 

使用環境:

            recyclerView + CardView 確實配,但不配合使用也沒什麼,所以別說絕配什麼的。

使用方法:

          1 屬性:

<resources>
    <declare-styleable name="CardView">
        <!-- Background color for CardView. -->
        <!-- 設置背景色 -->
        <attr name="cardBackgroundColor" format="color" />
        <!-- Corner radius for CardView. -->
        <!-- 設置圓角大小 -->
        <attr name="cardCornerRadius" format="dimension" />
        <!-- Elevation for CardView. -->
        <!-- 設置Z軸陰影高度 -->
        <attr name="cardElevation" format="dimension" />
        <!-- Maximum Elevation for CardView. -->
        <!-- 設置Z軸陰影最大高度 -->
        <attr name="cardMaxElevation" format="dimension" />
        <!-- Add padding in API v21+ as well to have the same measurements with previous versions. -->
        <!-- 設置內邊距,v21+的版本和之前的版本仍舊具有一樣的計算方式 -->
        <attr name="cardUseCompatPadding" format="boolean" />
        <!-- Add padding to CardView on v20 and before to prevent intersections between the Card content and rounded corners. -->
        <!-- 在v20和之前的版本中添加內邊距,這個屬性是爲了防止卡片內容和邊角的重疊 -->
        <attr name="cardPreventCornerOverlap" format="boolean" />
        <!-- 下面是卡片邊界距離內部的距離-->
        <!-- Inner padding between the edges of the Card and children of the CardView. -->
        <attr name="contentPadding" format="dimension" />
        <!-- Inner padding between the left edge of the Card and children of the CardView. -->
        <attr name="contentPaddingLeft" format="dimension" />
        <!-- Inner padding between the right edge of the Card and children of the CardView. -->
        <attr name="contentPaddingRight" format="dimension" />
        <!-- Inner padding between the top edge of the Card and children of the CardView. -->
        <attr name="contentPaddingTop" format="dimension" />
        <!-- Inner padding between the bottom edge of the Card and children of the CardView. -->
        <attr name="contentPaddingBottom" format="dimension" />
    </declare-styleable>
</resources>

         2 使用方法:

//列表配置
    implementation 'com.android.support:cardview-v7:26.1.0'

           xml佈局中:

<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto">

    <data>

        <variable
            name="adapter"
            type="com.tongyonghangkong.ui.adapter.DayAndDayTextAdapter" />

        <variable
            name="bean"
            type="String" />
    </data>

    <android.support.v7.widget.CardView
        android:layout_width="match_parent"
        android:layout_height="@dimen/onehundredSixty"
        android:foreground="?attr/selectableItemBackground"
        android:gravity="center"
        android:layout_margin="@dimen/fifteen"
        android:orientation="vertical"
        app:cardBackgroundColor="#FFFFFF"
        app:cardCornerRadius="15dp"
        app:cardMaxElevation="3dp"
        app:cardElevation="3dp">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:gravity="center_vertical"
            android:orientation="vertical">

            <ImageView
                android:id="@+id/ivModule"
                android:layout_width="match_parent"
                android:layout_height="0dp"
                android:layout_weight="1"
                android:scaleType="centerCrop"
                android:src="@drawable/icon_girl" />

            <TextView
                android:id="@+id/tvModuleFuncationName"
                style="@style/module_style_text_tv_1_12"
                android:text="@string/module_str_love_counseling" />

        </LinearLayout>
    </android.support.v7.widget.CardView>
</layout>

      效果:                    

                                              

   注意事項: cardView下只能展示一個佈局,所以需要使用常用的LinerLayout / RelativeLayout等等……

 

 

 

 

 

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章