android 伸缩工具栏,Android----Material Design之(FloatActionButton,CoordinatorLayout,CollapsingToolbarLayou...

Material Design 的一些UI 平常开发还是用的比较多的,以前没写,最近总结一下,写一篇博客,要求版本在5.0以上。

主要介绍了FloatActionButton,CoordinatorLayout,CollapsingToolbarLayout,AppBarLayout,Toolbar,TabLayout,RecyclerView,CardView

案例中包含了这些的使用;

使用前在build.gradle 添加

compile 'com.android.support:appcompat-v7:24.2.1'

compile 'com.jaeger.statusbaruitl:library:1.1.1'

compile 'com.android.support:design:24.2.+'

compile 'com.android.support:cardview-v7:24.2.1'

1:FloatActionButton(悬浮按钮)

FloatActionButton是ImageButton的继承类,其用法跟普通的Button基本类似,悬浮的效果,故其使用的重点其实是在布局上。

效果如图:

3edd74b959c2208167d9e7519fec12b2.gif

android:id="@+id/fab"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_margin="15dp"

android:layout_gravity="bottom|right"

app:fabSize="normal"

app:elevation="6dp"

android:src="@mipmap/ic_launcher"

app:pressedTranslationZ="25dp"

/>

结合Snackbar使用

属性介绍:

1、app:borderWidth=""------------------边框宽度,通常设置为0 ,用于解决Android 5.X设备上阴影无法正常显示的问题

2、app:backgroundTint=""---------------按钮的背景颜色,不设置,默认使用theme中colorAccent的颜色

3、app:rippleColor=""--------------------点击的边缘阴影颜色

4、app:elevation=""----------------------边缘阴影的宽度

5、app:pressedTranslationZ="16dp"-----点击按钮时,按钮边缘阴影的宽度,通常设置比elevation的数值大

2:CoordinatorLayout+AppBarLayout+CollapsingToolbarLayout(工具栏伸缩折叠)

实现Material Design里折叠工具栏,它继承至FrameLayout,给它设置layout_scrollFlags,

它可以控制包含在CollapsingToolbarLayout中的控件(如:ImageView、Toolbar)在响应layout_behavior事件时作出相应的scrollFlags滚动事件(移除屏幕或固定在屏幕顶端)。

效果如图:

92f0e536889bc982454b688c87ebffa5.gif

实现效果图的代码:

xmlns:android="http://schemas.android.com/apk/res/android"

xmlns:app="http://schemas.android.com/apk/res-auto"

android:id="@+id/main_content"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:fitsSystemWindows="true">

android:id="@+id/appbar"

android:layout_width="match_parent"

android:layout_height="226dp"

android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"

android:fitsSystemWindows="true">

android:id="@+id/collapsing_toolbar"

android:layout_width="match_parent"

android:layout_height="match_parent"

app:layout_scrollFlags="scroll|exitUntilCollapsed"

android:fitsSystemWindows="true"

app:contentScrim="?attr/colorPrimary"

app:expandedTitleMarginStart="48dp"

app:expandedTitleMarginEnd="64dp">

app:layout_scrollFlags="scroll|enterAlways|enterAlwaysCollapsed"

android:id="@+id/backdrop"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:scaleType="centerCrop"

android:fitsSystemWindows="true"

android:src="@mipmap/zhangwo_hometop1"

app:layout_collapseMode="parallax"

/>

android:id="@+id/toolbar"

android:layout_width="match_parent"

android:layout_height="?attr/actionBarSize"

app:popupTheme="@style/ThemeOverlay.AppCompat.Light"

app:layout_collapseMode="pin" />

android:layout_width="match_parent"

android:layout_height="match_parent"

app:layout_behavior="@string/appbar_scrolling_view_behavior">

android:id="@+id/recyclerView"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:scrollbars="none" />

android:id="@+id/fab"

android:layout_height="wrap_content"

android:layout_width="wrap_content"

app:layout_anchor="@id/appbar"

app:layout_anchorGravity="bottom|right|end"

android:src="@mipmap/ic_launcher"

android:layout_margin="15dp"

android:clickable="true"/>

3:CoordinatorLayout+AppBarLayout+TabLayout(工具栏伸缩折叠)

CoordinatorLayout是support.design包中的控件,它可以说是Design库中最重要的控件,

CoordinatorLayout 实现了多种Material Design中提到的滚动效果。

效果图:

c6f8617fef2d4165ae9fb3a24d2d2b34.gif

效果图布局

xmlns:android="http://schemas.android.com/apk/res/android"

xmlns:app="http://schemas.android.com/apk/res-auto"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:orientation="vertical">

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

android:id="@+id/appbar_toolbar"

app:layout_scrollFlags="scroll|enterAlways"

app:popupTheme="@style/Theme.AppCompat.Light"

android:layout_width="match_parent"

android:layout_height="?attr/actionBarSize"

android:background="?attr/colorPrimary" />

android:id="@+id/tabs"

app:tabGravity="fill"

app:tabMode="fixed"

android:layout_width="match_parent"

android:layout_height="wrap_content" />

android:id="@+id/viewpager"

android:layout_width="match_parent"

android:layout_height="match_parent"

app:layout_behavior="@string/appbar_scrolling_view_behavior" />

其他相关请看博客:

由于代码太多,就不一一贴出来了,源码直接下载即可

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值