一、介绍:CardView可以实现卡片布局,拥有圆角和阴影效果
1.导入包
implementation 'com.android.support:cardview-v7:27.1.1'
一般配合RecyclerView ,和Glide(图片加载库)使用
implementation 'com.android.support:recyclerview-v7:27.1.1'
/*图片加载库*/
compile 'com.github.bumptech.glide:glide:3.7.0'
2.基本用法,其实也是一个FrameLayout布局
app:cardCornerRadius="4dp" 设置圆角
android:elevation="5dp" 设置阴影/高度
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" xmlns:app="http://schemas.android.com/apk/res-auto" app:cardCornerRadius="4dp" android:elevation="5dp"> <TextView android:id="@+id/info_text" android:layout_width="match_parent" android:layout_height="wrap_content" /> </android.support.v7.widget.CardView>
3.方法
//实例化
cardView = (CardView)findViewById(R.id.cardView);
cardView.setRadius(8); //设置图片圆角的半径大小
cardView.setCardElevation(8); //设置阴影部分大小
cardView.setContentPadding(5,5,5,5); //设置图片距离阴影大小
CardView难度不大,不举例子了