android 5.0版本中新增了CardView, CardView继承自FrameLayout类,可以在一个卡片布局中一致性的显示内容,卡片可以包含圆角和阴影。也可以布局其他View。
如果sdk低于5.0我们仍旧要引入v7包,我用的是android studio所以我们需要在build.gradle加入如下代码用来自动导入support-v7包,记得配置完后重新Build一下工程。
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:22.2.1'
compile 'com.android.support:cardview-v7:22.1.0'
}
先看看布局:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="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:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".CardViewActivity"
android:orientation="vertical">
<android.support.v7.widget.CardView
android:id="@+id/tv_item"
android:layout_width="match_parent"
android:layout_height="250dp"
android:layout_centerInParent=

本文介绍了Android 5.0引入的CardView组件,它是FrameLayout的扩展,提供圆角和阴影效果,用于统一内容展示。在SDK版本较低时,需要引入v7包。文章详细讲解了如何在build.gradle中配置支持库,并展示了CardView的重要属性如cardCornerRadius和cardElevation的使用。通过Java代码示例,演示了如何动态调整CardView的圆角半径、阴影半径和内容内边距,最后展示了运行效果并提供了源码下载。
最低0.47元/天 解锁文章
1522

被折叠的 条评论
为什么被折叠?



