Android 基础:Materia Design 定义视图阴影elevation和创建卡片CardView
新的 translationZ 属性使得你可以设计临时变更 elevation 的动画。elevation 变化在做触摸反馈时很有用。
创建列表和卡片
=======
RecyclerView 是一个可插入性更强的 ListView,它支持不同的 layout 类型,并可以提升性能。CardView 使得你可以在卡片
内显示一部分内容,并且和其他应用保持外观一致。以下是一段样例代码展示如何在 layout 中添加 CardView。
<android.support.v7.widget.CardView
android:id="@+id/card_view"
android:layout_width=“200dp”
android:layout_height=“200dp”
card_view:cardCornerRadius=“3dp”>
…
</android.support.v7.widget.CardView>
其中 card_view:cardCornerRadius 属性是改变卡片的四个角的半径的,如圆角,直角等。
下面通过官网的一个Sample来实例演示
====================
效果图
项目结构
代码
–
activity_card_view.xml:
<FrameLayout xmlns:android=“http://schemas.android.com/apk/res/android”
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/container"
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="com.example.android.cardview.CardViewActivity"
tools:ignore="MergeRootFrame" />
fragment_card_view:
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:layout_height="match_parent"
android:layout_width="match_parent"
>
<LinearLayout android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
>
<android.support.v7.widget.CardView
android:id="@+id/cardview"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:elevation="100dp"
card_view:cardBackgroundColor="@color/cardview_initial_background"
card_view:card
《Android学习笔记总结+最新移动架构视频+大厂安卓面试真题+项目实战源码讲义》
【docs.qq.com/doc/DSkNLaERkbnFoS0ZF】 完整内容开源分享
CornerRadius=“8dp”
android:layout_marginLeft="@dimen/margin_large"
android:layout_marginRight="@dimen/margin_large"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="@dimen/margin_medium"
android:text="@string/cardview_contents"
/>
</android.support.v7.widget.CardView>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/margin_large"
android:orientation="horizontal"
>
<TextView
android:layout_width="@dimen/seekbar_label_length"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:text="@string/cardview_radius_seekbar_text"
/>
<SeekBar
android:id="@+id/cardview_radius_seekbar"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="@dimen/margin_medium"
/>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
>
<TextView
android:layout_width="@dimen/seekbar_label_length"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:text="@string/cardview_elevation_seekbar_text"
/>
<SeekBar
android:id="@+id/cardview_elevation_seekbar"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="@dimen/margin_medium"
/>
</LinearLayout>
</LinearLayout>
CardViewActivity:
public class CardViewActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_card_view);
if (savedInstanceState == null) {
getFragmentManager().beginTransaction()
.add(R.id.container, CardViewFragment.newInstance())
.commit();
}
}
}
CardViewFragment:
public class CardViewFragment extends Fragment {
private static final String TAG = CardViewFragment.class.getSimpleName();
/** The CardView widget. */
//@VisibleForTesting
CardView mCardView;
/**
* SeekBar that changes the cornerRadius attribute for the {@link #mCardView} widget.
*/
//@VisibleForTesting
SeekBar mRadiusSeekBar;
/**
* SeekBar that changes the Elevation attribute for the {@link #mCardView} widget.
*/
//@VisibleForTesting
SeekBar mElevationSeekBar;
/**
* Use this factory method to create a new instance of
Android 基础:Materia Design 定义视图阴影elevation和创建卡片CardView相关推荐
- android 基础 materia design 设计
material design颜色选择 700 500 100 material design字体大小 最基本的样式集合就是基于12.14.16.20和34号的字体排版缩放. 英文字体使用Ro ...
- android 重置画布,android-自定义视图:重按视图画布
多亏了pskink,我才能够创建完整的解决方案. 如果要创建自定义视图,其中必须是针对不同触摸状态(按下,选定,聚焦等)的自定义工程图,并且您不知道此视图是否将放置在其他可以拦截触摸事件的视图中,或者 ...
- ANDROID L——Material Design详解(视图和阴影)
转载请注明本文出自大苞米的博客(http://blog.csdn.net/a396901990),谢谢支持! Android L: Google已经确认Android L就是Android Lolli ...
- 【Android】AppCompat V21:将 Materia Design 兼容到5.0之前的设备
AppCompat V21:将 Materia Design 兼容到于5.0之前的设备 本篇文章翻译自Chris Banes(就职于Google,是Android-PullToRefresh,Phot ...
- Android基础入门教程——2.4.13 ViewFlipper(翻转视图)的基本使用
Android基础入门教程--2.4.13 ViewFlipper(翻转视图)的基本使用 标签(空格分隔): Android基础入门教程 本节引言: 本节给大家带了的是ViewFlipper,它是An ...
- ANDROID L——Material Design详解(主题和布局)
转载请注明本文出自大苞米的博客(http://blog.csdn.net/a396901990),谢谢支持! Android L: Google已经确认Android L就是Android Lolli ...
- Mono.Android 基础
Mono.Android 基础 (地址) Mono.Android项目结构是 - Project+ Assets+ Resources+ drawable+ layout+ valuesResourc ...
- 【Android】你可能还不知道的elevation、以及Z值等
Android你可能还不知道的elevation以及Z值等 elevation以及Z值是什么 有什么用处呢 影响View的阴影 影响View相互阻挡顺序 还有CardView [Android]你可能 ...
- 重学Android基础系列篇(五):Android虚拟机指令
前言 本系列文章主要是汇总了一下大佬们的技术文章,属于Android基础部分,作为一名合格的安卓开发工程师,咱们肯定要熟练掌握java和android,本期就来说说这些~ [非商业用途,如有侵权,请告 ...
最新文章
- COJ 1163 乘法逆元的求解
- ROS系统中的多个版本Boost问题
- 【kali】kali环境下安装dvwa
- HDU 4190 Distributing Ballot Boxes【二分答案】
- 二叉树---树的深度递归理解
- pulse 去马赛克软件_最新黑科技...马赛克也能去了!!
- OpenShift 4 - 多云管理(2) - 部署应用
- 小李飞刀:SQL题目刷起来!
- chrome怎么调用硬件_浏览器发展简史——IE帝国是如何被chrome打败的?
- python 把4个二进制组成float_4个方法用Python自由定制Excel表格
- 编程小工具总结(一) 取色器
- Arduino 交通灯实验
- win10开启无线网卡服务器,Win10笔记本电脑无线网卡 教你如何开启Win10笔记本内置无线网卡...
- Mysql-explain-Impossible WHERE noticed after reading const tables
- 不要让刷单限制了你的运营能力,零基础店铺流量爆发技巧!
- 突然间思考PID 有意思的地方-为什么说开环控制最优这句话也对也不对
- “法外狂徒”为什么那么多?用程序来告诉你!
- 可维护性、可复用性和可扩展性的区别
- 伯南克回忆2008:金融危机如何演变为经济危机?------From凤凰财经20160430
- oracle-SQL存储过程
热门文章
- java设计模式——门面与调停
- lammps案例分析(2):石墨烯单轴拉伸之deform方式
- 弥散磁共振成像在神经科学中的应用
- Romi Robot Kit (for FIRST) 快速入门指南
- mysql 时间连续性查询_MYSQL 连续性问题求解
- 科卡在线linux,典型建网方案之家庭内部网设计
- Linux 离线安装.net sdk
- BZOJ 4407于神之怒加强版
- 刘振飞:躲在镜子背后听用户反馈
- Model-Agnostic Meta-Learning for Fast Adaptation of Deep Networks阅读笔记