CardView 整理
卡片布局 CardView
属性 | 描述 |
---|---|
app:cardCornerRadius | 设置圆角半径 |
app:cardElevation | 设置阴影大小 |
app:cardBackgroundColor | 设置背景颜色 |
app:cardMaxElevation | 设置最大阴影大小 |
app:cardPreventCornerOverlap | 设置添加内边距,防止重叠。默认 true |
app:cardUseCompatPadding | 是否使用Padding |
app:contentPadding | 设置Padding大小 |
app:contentPaddingLeft | 设置左Padding大小 |
app:contentPaddingRight | 设置右Padding大小 |
app:contentPaddingTop | 设置上Padding大小 |
app:contentPaddingBottom | 设置下Padding大小 |
依赖必不可少
implementation ‘com.android.support:cardview-v7:28.0.0’
布局文件
<?xml version="1.0" encoding="utf-8"?>
<LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"xmlns:app="http://schemas.android.com/apk/res-auto"xmlns:tools="http://schemas.android.com/tools"android:layout_width="match_parent"android:layout_height="match_parent"tools:context="com.example.test.MainActivity"><LinearLayoutandroid:layout_width="match_parent"android:layout_height="match_parent"android:orientation="vertical"><android.support.v7.widget.CardViewandroid:id="@+id/cardview"android:layout_width="match_parent"android:layout_height="300dp"android:layout_margin="15dp"app:cardCornerRadius="10dp"app:cardElevation="10dp"app:cardBackgroundColor="@color/gray"app:cardMaxElevation="30dp"app:cardPreventCornerOverlap="false"app:cardUseCompatPadding="true"app:contentPadding="10dp"app:contentPaddingLeft="10dp"app:contentPaddingRight="10dp"app:contentPaddingTop="10dp"app:contentPaddingBottom="10dp"><ImageViewandroid:layout_margin="10dp"android:layout_width="match_parent"android:layout_height="match_parent"android:src="@drawable/bg"android:scaleType="centerInside"/></android.support.v7.widget.CardView><LinearLayoutandroid:layout_width="match_parent"android:layout_height="50dp"android:orientation="vertical"android:layout_margin="10dp"><SeekBarandroid:id="@+id/seekbar_one"android:layout_width="match_parent"android:layout_height="wrap_content"/><TextViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:text="调整圆角大小"/></LinearLayout><LinearLayoutandroid:layout_width="match_parent"android:layout_height="50dp"android:orientation="vertical"android:layout_margin="10dp"><SeekBarandroid:id="@+id/seekbar_two"android:layout_width="match_parent"android:layout_height="wrap_content"/><TextViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:text="调整阴影大小"/></LinearLayout></LinearLayout></LinearLayout>
CardView 中包裹了一张图片,并设置了相应的属性。
通过SeekBar控制圆角大小和阴影
代码中如下:
public class MainActivity extends AppCompatActivity {@BindView(R.id.seekbar_one)SeekBar mSeekbarOne;@BindView(R.id.seekbar_two)SeekBar mSeekbarTwo;@BindView(R.id.cardview)CardView mCardview;private Unbinder mUnbinder;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);mUnbinder = ButterKnife.bind(this);initView();}private void initView() {mSeekbarOne.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {@Overridepublic void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {mCardview.setRadius(progress);}@Overridepublic void onStartTrackingTouch(SeekBar seekBar) {}@Overridepublic void onStopTrackingTouch(SeekBar seekBar) {}});mSeekbarTwo.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {@Overridepublic void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {mCardview.setCardElevation(progress);}@Overridepublic void onStartTrackingTouch(SeekBar seekBar) {}@Overridepublic void onStopTrackingTouch(SeekBar seekBar) {}});}@Overrideprotected void onDestroy() {super.onDestroy();mUnbinder.unbind();}
}
运行 效果图如下:
CardView 整理相关推荐
- 最全收集整理GitHub上受欢迎的Android UI Library
抽屉菜单 ListView WebView SwitchButton 按钮 点赞按钮 进度条 TabLayout 图标 下拉刷新 ViewPager 图表(Chart) 菜单(Menu) 浮动菜单 对 ...
- Android最牛的开源整理
这是一个基本把github上所有优秀安卓的开源代码整理了,下面是都是转自https://github.com/Trinea/android-open-project,都是一些牛人,很有开源精神的达人做 ...
- android 常用框架整理
文章目录 UI 框架 WebView 框架 具体内容 UI 卫星菜单 节选器 下拉刷新 模糊效果 HUD与Toast 进度条 UI其他 动画 网络相关 网络连接 网络测试 图像获取 响应式编程 地图 ...
- Bootstrap Table使用整理(一)
一.Bootstrap Table相关整理 基于 Bootstrap 的 jQuery 表格插件,通过简单的设置,就可以拥有强大的单选.多选.排序.分页,以及编辑.导出.过滤(扩展)等等的功能. 1. ...
- CardView背景色无效的解决方式
想看更多算法题,可以扫描上方二维码关注我微信公众号"数据结构和算法",截止到目前我已经在公众号中更新了500多道算法题,其中部分已经整理成了pdf文档,截止到目前总共有800多页( ...
- Android 开源项目整理
这是一个基本把github上所有优秀安卓的开源代码整理了,下面是都是转自https://github.com/Trinea/Android-open-project,都是一些牛人,很有开源精神的达人做 ...
- 整理下维护别人项目遇到的Bug或者错误写法
Fragment already added 异常 java.lang.IllegalStateException: Fragment already added 修改前代码如下 FragmentTr ...
- 关于android相关开发资料的整理
权限 适配Android6.0动态权限管理 FcPermissions:也许是目前最好的动态权限请求库 Android 开发技巧 - Android 6.0 以上权限大坑和权限检查基类封装 Andro ...
- Map再整理,从底层源码探究HashMap
前言 本文为对Map集合的再一次整理.内容包括:Map HashMap LinkedHashMap TreeHashMap HashTable ConcurrentHashMap Map Map< ...
- List再整理,从代码底层全面解析List(看完后保证收获满满)
前言 本文为对List集合的再一次整理,从父集接口Collection到顶级接口Iterable再到线程不安全实现类:ArrayList.LinkedList,再到线程安全实现类:Vector(被弃用 ...
最新文章
- linux查找大文件
- 偶然发现了获取有ID的dom的一种方法
- 树状数组(单点+区间的所有操作)
- 【IDEA】干掉注释自动在行首
- 异动分析技术解决方案—异动归因之指标拆解
- redis持久化之rdb篇
- 杂记 - 进化成更好的人
- PyCharm新建项目-运行第一个helllo Python程序
- 【智力题】拿硬币(数数字)、游戏
- hdu4318 最短路变形
- 敏感词库php数组,PHP 实现敏感词 / 停止词 过滤(附敏感词库),敏感类词语大全...
- 智能水表营收管理系统
- 泛微E9升级KB包方法
- 各种Android实现边框
- 2018 Macbook pro 15(10.13.6)安装Nvidia 1070(Aorus Gaming Box)显卡驱动
- speedoffice(PPT)怎么给文字加粗
- matlab 斜坡信号响应,matlab斜坡输入响应
- 随想,产品思维和开发思维
- 数据数仓的三种建模方式
- 【BOOST C++字串专题11】Boost.Spirit(二)