zoukankan      html  css  js  c++  java
  • CardView的使用(可以实现圆角控件)

    简介:ardView继承自FrameLayout,它是一个带圆角背景和阴影的FrameLayout

    一些什么实现方式就不赘述了,直接上用法

    CardView的常用属性

      1、设置背景颜色 

    app:cardBackgroundColor=" "

    2、设置padding
    app:contentPadding=" "
    app:contentPaddingTop=" "
    app:contentPaddingBottom=" "
    app:contentPaddingLeft=" "
    app:contentPaddingRight=" "

    注意啊:上面是CardView设置背景颜色和padding的方式,如果你直接通过android:padding=" " 和android:background=" "设置,是无效的

    3、设置Z轴的最大高度
    app:cardMaxElevation=" "

    4、点击之后的涟漪效果
    android:clickable="true"
    android:foreground="android:attr/selectableItemBackground"
    
    注意:如果你给CardView设置了点击事件,就不需要设置android:clickable="true"了

    5.设置CardView的圆角半径

    app:cardCornerRadius =""

    6设置CardView的前景

    android:foreground =""

    7设置内边距

    app:contentPadding ="

    例如在项目中的用法
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        xmlns:card_view="http://schemas.android.com/apk/res-auto"
        ... >
        <!-- A CardView that contains a TextView -->
        <android.support.v7.widget.CardView
            xmlns:card_view="http://schemas.android.com/apk/res-auto"
            android:id="@+id/card_view"
            android:layout_gravity="center"
            android:layout_width="200dp"
            android:layout_height="200dp"
            card_view:cardCornerRadius="4dp">
    
            <TextView
                android:id="@+id/info_text"
                android:layout_width="match_parent"
                android:layout_height="match_parent" />
        </android.support.v7.widget.CardView>
    </LinearLayout>
    

    总结:注意这个控件在5.0之下会有包裹不均匀的现象,但是在5.0之上会很好用

    可以控制这个属性来适配app:cardPreventCormorOverlap

    true:防止子View被CardView的圆角进行剪切 false: 允许剪切,主要用于适配Lollipop以下

    by磊磊tua
  • 相关阅读:
    在归并排序中对小数组采用插入排序实现代码
    PAT 1032. Sharing
    1031. Hello World for U
    PAT 1030. Travel Plan
    PAT 1029. Median
    PAT 1028. List Sorting
    PAT 1027. Colors in Mars
    PAT 1026. Table Tennis
    PAT 1025. PAT Ranking
    Several Important Commands in GMT
  • 原文地址:https://www.cnblogs.com/widgetbox/p/11428542.html
Copyright © 2011-2022 走看看