CardView

简介: CardView效果图依赖dependencies { …… compile 'com.

CardView

效果图

P1

依赖

dependencies {
    ……
    compile 'com.android.support:cardview-v7:23.0.+'
}

Code

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:kongqw="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context="com.kongqw.cardviewdemo.MainActivity">

    <android.support.v7.widget.CardView
        android:layout_width="match_parent"
        android:layout_height="150dp"
        android:layout_margin="20dp"
        kongqw:cardBackgroundColor="#FF00AABB"
        kongqw:cardCornerRadius="30dp"
        kongqw:cardElevation="20dp">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:text="CardView"
            android:textColor="#FF000000"
            android:textSize="30dp" />

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

    <android.support.v7.widget.CardView
        android:layout_width="match_parent"
        android:layout_height="150dp"
        android:layout_margin="20dp"
        kongqw:cardCornerRadius="10dp"
        kongqw:cardElevation="10dp">

        <ImageView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@mipmap/bb" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:text="CardView"
            android:textColor="#FFFFFFFF"
            android:textSize="30dp" />

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

总结

XML属性

Attribute Name Related Method Description
android.support.v7.cardview:cardBackgroundColor setCardBackgroundColor(int) Background color for CardView.
android.support.v7.cardview:cardCornerRadius setRadius(float) Corner radius for CardView.
android.support.v7.cardview:cardElevation setMaxCardElevation(float) Elevation for CardView.
android.support.v7.cardview:cardMaxElevation Maximum Elevation for CardView.
android.support.v7.cardview:cardPreventCornerOverlap setPreventCornerOverlap(boolean) Add padding to CardView on v20 and before to prevent intersections between the Card content and rounded corners.
android.support.v7.cardview:cardUseCompatPadding setUseCompatPadding(boolean) Add padding in API v21+ as well to have the same measurements with previous versions.
android.support.v7.cardview:contentPadding setContentPadding(int,int,int,int) Inner padding between the edges of the Card and children of the CardView.
android.support.v7.cardview:contentPaddingBottom setContentPadding(int,int,int,int) Inner padding between the bottom edge of the Card and children of the CardView.
android.support.v7.cardview:contentPaddingLeft setContentPadding(int,int,int,int) Inner padding between the left edge of the Card and children of the CardView.
android.support.v7.cardview:contentPaddingRight setContentPadding(int,int,int,int) Inner padding between the right edge of the Card and children of the CardView.
android.support.v7.cardview:contentPaddingTop setContentPadding(int,int,int,int) Inner padding between the top edge of the Card and children of the CardView.

方法

返回值类型 方法/描述
float getCardElevation()

Returns the backward compatible elevation of the CardView.
int getContentPaddingBottom()

Returns the inner padding before the Card’s bottom edge
int getContentPaddingLeft()

Returns the inner padding after the Card’s left edge
int getContentPaddingRight()

Returns the inner padding before the Card’s right edge
int getContentPaddingTop()

Returns the inner padding after the Card’s top edge
float getMaxCardElevation()

Returns the backward compatible elevation of the CardView.
boolean getPreventCornerOverlap()

Returns whether CardView should add extra padding to content to avoid overlaps with rounded corners on API versions 20 and below.
float getRadius()

Returns the corner radius of the CardView.
boolean getUseCompatPadding()

Returns whether CardView will add inner padding on platforms L and after.
void setCardBackgroundColor(int color)

Updates the background color of the CardView
void setCardElevation(float radius)

Updates the backward compatible elevation of the CardView.
void setContentPadding(int left, int top, int right, int bottom)

Sets the padding between the Card’s edges and the children of CardView.
void setMaxCardElevation(float radius)

Updates the backward compatible elevation of the CardView.
void setPadding(int left, int top, int right, int bottom)

Sets the padding.
void setPaddingRelative(int start, int top, int end, int bottom)

Sets the relative padding.
void setPreventCornerOverlap(boolean preventCornerOverlap)

On API 20 and before, CardView does not clip the bounds of the Card for the rounded corners.
void setRadius(float radius)

Updates the corner radius of the CardView.
void setUseCompatPadding(boolean useCompatPadding)

CardView adds additional padding to draw shadows on platforms before L.
相关文章
|
1月前
|
Android开发
[Android]DrawerLayout滑动菜单+NavigationView
[Android]DrawerLayout滑动菜单+NavigationView
41 0
|
API Android开发
CardView的那点事儿
CardView的那点事儿
90 0
|
开发工具 Android开发
RecyclerView与CardView的使用(一)
RecyclerView与CardView的使用(一)
137 0
RecyclerView与CardView的使用(一)
RecyclerView与CardView的使用(二)
RecyclerView与CardView的使用(二)
107 0
RecyclerView与CardView的使用(二)
|
Android开发
CoordinatorLayout使用浅析
CoordinatorLayout使用浅析
195 0
CoordinatorLayout使用浅析
|
Android开发
2-VVI-材料设计之CardView
零、前言 [1].CardView extends FrameLayout [2].一个带圆角和阴影的FrameLayout,FrameLayout怎么用,它就怎么用 [3].
1094 0
CoordinatorLayout 之深入理解
上篇在对 CoordinatorLayout 作了一些简单介绍,以了解 CoordinatorLayout 带来的一些特性和常见用途。本篇将对 CoordinatorLayout 的源码进行一些分析,以了解它的相关特性的运行原理,以及 Behavior 的执行过程。
1297 0