Android控件CardView实现卡片效果
作者:cf8833 发布时间:2023-09-05 17:01:16
标签:Android,CardView,卡片
这是android新推出的一个,让卡片带立体感的一个控件,就是一个卡牌,有点类似于布局那种的东西,里面可以添加控件内容
先看看运行的效果图:
1.添加依赖
implementation 'com.android.support:cardview-v7:25.3.1'
2.主界面设置一些卡片的属性:
package com.example.admin.ztest;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.CardView;
/*
app:cardBackgroundColor这是设置背景颜色
app:cardCornerRadius这是设置圆角大小
app:cardElevation这是设置z轴的阴影
app:cardMaxElevation这是设置z轴的最大高度值
app:cardUseCompatPadding是否使用CompatPadding
app:cardPreventCornerOverlap是否使用PreventCornerOverlap
app:contentPadding 设置内容的padding
app:contentPaddingLeft 设置内容的左padding
app:contentPaddingTop 设置内容的上padding
app:contentPaddingRight 设置内容的右padding
app:contentPaddingBottom 设置内容的底padding
*/
public class MainActivity extends AppCompatActivity {
CardView cardView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_first);
cardView = (CardView) findViewById(R.id.cardView);
cardView.setRadius(8);//设置图片圆角的半径大小
cardView.setCardElevation(8);//设置阴影部分大小
cardView.setContentPadding(5, 5, 5, 5);//设置图片距离阴影大小
}
}
布局页面:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/cardView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="10dp"
app:cardCornerRadius="8dp">
<LinearLayout
android:layout_width="600pt"
android:layout_height="100pt"
android:background="@drawable/bg_battery_detail"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_marginTop="5dp"
android:background="#184467">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:orientation="horizontal">
<TextView
android:id="@+id/tvBatteryNo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:text="电池编号"
android:textColor="@color/color_z2"
android:textSize="20sp" />
<TextView
android:id="@+id/tvBatterySlotNo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginLeft="15pt"
android:text="@string/app_name"
android:textColor="@color/white"
android:textSize="20sp" />
</LinearLayout>
<ImageView
android:id="@+id/ivCloseDialog"
android:layout_width="39pt"
android:layout_height="39pt"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="8pt"
android:padding="7pt"
android:src="@mipmap/popup_del" />
</RelativeLayout>
</LinearLayout>
</android.support.v7.widget.CardView>
来源:https://blog.csdn.net/cf8833/article/details/90514220


猜你喜欢
- 我们知道Android手机操作系统采用的是Linux内核,Linux中最高的系统权限就是Root,这就类似与Windows中的Adminis
- Android SharedPreferences详解获取SharedPreferences的两种方式:1 调用Context对
- 前言大家或许在iOS程序开发中经常遇到屏幕旋转问题,比如说希望指定的页面进行不同的屏幕旋转,但由于系统提供的方法是导航控制器的全局方法,无法
- 网上各种解决方案,我试了好久,整合了几篇文章才凑出来,在这里分享一下,实在不想网友们在这里面绕圈子,毕竟,写代码的时间是愉快的,解决bug也
- 正常在Java工程中读取某路径下的文件时,可以采用绝对路径和相对路径,绝对路径没什么好说的,相对路径,即相对于当前类的路径。在本地工程和服务
- 打包发布jar包部署相对较为简单,尤其是在分布式服务比较多的情况下。单体项目如果是单体项目,只需要找到maven的插件,点击package运
- 一个项目可能会有不同的环境,例如dev/stating/prod等,不同的环境的配置文件是不同的,如何根据环境快速的切换到对应的配置文件很重
- 介绍单例模式是软件工程学中最富盛名的设计模式之一。从本质上看,单例模式只允许被其自身实例化一次,且向外部提供了一个访问该实例的接口。通常来说
- 简单介绍快速排序(Quicksort) 是对 冒泡排序的一种改进。基本思想快速排序算法通过多次比较和交换来实现排序,其排序流程如下:(1)首
- 今天,我们接着讲微信支付的系列教程,前面,我们讲了这个微信红包和扫码支付。现在,我们讲讲这个公众号支付。公众号支付的应用环境常见的用户通过公
- Java的List在删除元素时,一般会用list.remove(o)/remove(i)方法。在使用时,容易触碰陷阱,得到意想不到的结果。总
- 本文为大家分享了NancyFx框架检测任务管理器的具体方法,供大家参考,具体内容如下先建一个空的项目和之前的NancyFx系列一样的步骤然后
- SpringBoot下载Excel文件文件损坏我把模板文件放在了resources目录下maven插件打包项目的时候,默认会压缩resour
- 一、引言“为什么我们需要掌握互操作技术的呢?” 对于这个问题的解释就是—&
- 生命太短暂,不要去做一些根本没有人想要的东西。本文已被 https://www.yourbatman.cn 收录,里面一并有Spring技术
- Fragment 的简单用法Fragment 是一种可以嵌入在 Activity 当中的 UI 片段,它能让程序更加合理和充分地利用大屏幕的
- Oracle官网是这样介绍默认方法的,使用默认方法,可以达到往接口里面增加新的功能,而且保持与老版本代码兼容,也就是原来的实现类可以不需要被
- 本文实例为大家分享了Java执行SQL脚本文件到数据库的具体方式,供大家参考,具体内容如下方式一:直接读取SQL脚本文件的内容,然后传递到S
- 由于springboot常用war包部署,改为cloud开发模式多端口情况下,部署反而不习惯毕竟,war包要不要项目名访问都必须放在tomc
- 什么是XML?XML:可扩展标记语言。XML的作用:纯文本,兼容性强。和HTML的区别:xml: 主要用来处理、存储数据。无规定标签,可扩展