Android CardView 和Material Design风格设计学习

这篇文章主要介绍一下我自己对于CardView和Material Design学习的过程。学习途径主要是通过书本和网上资料学习。

效果图:

这里写图片描述

这里写图片描述

这里写图片描述

说明一下,通过下拉可以让我们宇宙的图片拉伸延展出来,通过上滑,可以让我们宇宙图片逐渐变换成ToolBar样式。
一.什么是Material Design:
Material Design,中文名:材料设计语言,是由Google推出的全新的设计语言,谷歌表示,这种设计语言旨在为手机、平板电脑、台式机和“其他平台”提供更一致、更广泛的“外观和感觉”。
个人感觉这样的界面设计可以使得我们的APP界面更加的统一和美观。

二.什么是CardView:
卡片布局,从名字中就能感受到界面的划分以卡片形式为主,并且通过其属性设置,可以更大程度上满足我们对于卡片界面的设计。

三.学习过程:

首先我们先添加依赖:

  compile 'com.android.support:recyclerview-v7:25.1.1'
    compile 'com.android.support:cardview-v7:25.1.1'
    compile 'com.github.githubwing:ByeBurger:1.2.3'

这部分依赖是用于cardview和recyclerview包括coordinationlayout的依赖。

然后看一下布局文件:
recycler_view_item:

<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/card_view"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_margin="5dp"
    android:clickable="true"
    app:cardElevation="5dp"
    android:foreground="?attr/selectableItemBackground"
    app:cardCornerRadius="2dp">
<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical">
    <ImageView
        android:id="@+id/fruit_image"
        android:layout_width="match_parent"
        android:layout_height="100dp"
        android:scaleType="center"/>
    <TextView
        android:id="@+id/fruit_name"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="5dp"
        android:textSize="16sp"
        android:layout_gravity="center"/>
</LinearLayout>
</android.support.v7.widget.CardView>

可以看到,我们外层布局采用的是cardview布局,我们设置了它的阴影,圆角和边距,然后下面的控件就是具体item中显示的控件了。
这个布局文件也是我们图一种Recycler的Item的布局样式。

activity_main:

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/activity_main"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.example.adm
  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值