Android控件CardView实现卡片布局
作者:简单不一定不好 时间:2022-12-05 02:10:32
CardView介绍
CardView是Android 5.0系统引入的控件,相当于FragmentLayout布局控件然后添加圆角及阴影的效果;CardView被包装为一种布局,并且经常在ListView和RecyclerView的Item布局中,作为一种容器使用。CardView应该被使用在显示层次性的内容时;在显示列表或网格时更应该被选择,因为这些边缘可以使得用户更容易去区分这些内容。
使用
先看效果
首先在build.gradle文件添加依赖库
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:24.2.0'
compile 'com.android.support:cardview-v7:24.2.0'
}
布局文件main.html文件下
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.CardView
android:id="@+id/cardView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="100dp">
<ImageView
android:layout_width="150dp"
android:layout_height="match_parent"
android:layout_margin="5dp"
android:scaleType="centerCrop"
android:src="@drawable/sng" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="5dp"
android:text="棒冰行动"
android:textSize="18sp"
android:textStyle="bold" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="5dp"
android:text="棒冰行动,公益传播设计夏令营" />
</LinearLayout>
</LinearLayout>
</android.support.v7.widget.CardView>
</LinearLayout>
在MainActivity.java下文件
public class MainActivity extends AppCompatActivity {
private CardView cardView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
cardView = (CardView)findViewById(R.id.cardView);
cardView.setRadius(8);//设置图片圆角的半径大小
cardView.setCardElevation(8);//设置阴影部分大小
cardView.setContentPadding(5,5,5,5);//设置图片距离阴影大小
}
}
好,已结束CardView难度不大,当是实用性及及效果是非常棒的,值得你拥有!
来源:https://blog.csdn.net/u010498248/article/details/52524053?utm_source=blogxgwz7
标签:Android,CardView,卡片布局
0
投稿
猜你喜欢
C#读取txt文件数据的方法实例
2022-12-08 15:25:41
Android跳转到通讯录获取用户名称和手机号码的实现思路
2023-12-11 16:42:57
SpringMVC如何获取表单数据(radio和checkbox)
2022-02-19 05:27:01
IDEA插件EasyCode及MyBatis最优配置步骤详解
2023-11-09 03:19:19
Android开发之ListView的head消失页面导航栏的渐变出现和隐藏
2022-03-02 14:25:24
Java集合类中文介绍
2022-07-22 18:02:20
Android 中无法取消标题栏的问题小结(两种方法)
2021-06-25 19:45:02
C++实现哈夫曼树算法
2023-05-21 01:03:46
Android Studio 引用外部依赖时报错的解决方法
2023-09-26 18:20:11
java实现支付宝支付接口的调用
2023-10-13 09:43:40
Android Studio实现进度条效果
2021-10-12 05:37:17
Android 静默安装实现方法
2021-08-04 05:11:25
实例讲解JAVA设计模式之备忘录模式
2023-08-29 16:31:19
C#词法分析器之构造NFA详解
2022-04-10 02:11:43
C#中Equals方法的常见误解
2023-03-10 21:59:23
c#创建浮动工具栏功能示例
2022-08-31 01:08:31
解决Android从相册中获取图片出错图片却无法裁剪问题的方法
2023-09-14 23:41:15
Java多线程的实现方式比较(两种方式比较)
2023-06-06 13:00:12
Java中final与继承操作实例分析
2023-09-14 08:56:02
jpa多数据源时Hibernate配置自动生成表不生效的解决
2023-04-24 06:19:55