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
  • 相关阅读:
    .NET技术对软件行业的积极作用
    ADO.NET Entityframework MYSQL provider
    用杯子量水问题通用解法
    详解.NET异步
    说 框架、架构、模式、重构
    谈 三层结构与MVC模式的区别
    面试题一例分享
    LINQ notes2 lambda expression
    毕业论文B.3 DTW算法
    LINQ notes1 intro
  • 原文地址:https://www.cnblogs.com/widgetbox/p/11428542.html
Copyright © 2011-2022 走看看