Giter Club home page Giter Club logo

lbehavior's Introduction

LBehavior 简单实现标题栏、导航栏滑动动画

效果图

screenshot screenshot screenshot

博客介绍

简书:http://www.jianshu.com/p/2974d8ffc3a5

个人网站:http://lauzy.me/2017/04/14/Behavior/

Download

    allprojects {
	    repositories {
		    ...
		    maven { url 'https://jitpack.io' }
	    }
	}

    dependencies {
        compile 'com.android.support:design:25.3.1'(latestVersion)
        compile 'com.github.Lauzy:LBehavior:1.0.1'
	}

Usage

基本使用:

根布局需为CoordinatorLayout,类似FrameLayout

    <android.support.design.widget.CoordinatorLayout
        ...>
		<FloatingActionButton
 			...
			app:layout_behavior="@string/fab_vertical_behavior/>
    </android.support.design.widget.CoordinatorLayout>

根据不同的View在xml中设置不同的layout_behavior

参数 说明
@string/title_view_behavior 顶部标题栏
@string/bottom_view_behavior 底部导航栏
@string/fab_scale_behavior 浮动按钮(缩放)
@string/fab_vertical_behavior 浮动按钮(上下滑动)

自定义(均设有默认值,可不使用):

方法 参数 说明
setMinScrollY int y 设置触发动画的最小滑动距离,如 setMinScrollY(10)为滑动10像素才可触发动画,默认为5.
setScrollYDistance int y 设置触发动画的滑动距离,防止用户缓慢滑动时单次滑动距离一直小于setMinScrollY的最小滑动距离导致无法触发动画.如设置此值为100,则用户即便缓慢滑动,当滑动距离达到100时也可触发动画.默认为40.
setDuration int duration 设置动画持续时间.默认为400ms.
setInterpolator Interpolator interpolator 设置动画插补器,修饰动画效果.默认模式为LinearOutSlowInInterpolator. Interpolator官方文档
	CommonBehavior.from(mFloatingActionButton).show();//代码控制显示
	CommonBehavior.from(mFloatingActionButton).hide();//隐藏

	CommonBehavior.from(mFloatingActionButton)
		.setMinScrollY(20)
		.setScrollYDistance(100)
		.setDuration(1000)
		.setInterpolator(new LinearOutSlowInInterpolator());

Tips

1、因为根布局为CoordinatorLayout,所以使用时Toolbar可能会遮盖RecyclerView顶部的item,BottomBar也可能会遮盖底部item。 可以参考知乎首页设置顶部留白,具体可为RecyclerView添加一个占位的ItemDecoration,或者顶部加一个占位的View,若场景比较固定可简单设置Padding,Margin等, 详情可见Demo,简单处理了这种情况。

2、FloatingActionButton的elevation若大于BottomBar的elevation,则FloatingActionButton动画覆盖在BottomBar上层,反之则在下层,为gif的下部两个按钮的效果。

Apk and More Info

For more usage, you can download or clone the demo. You can also download the demo apk.

lbehavior's People

Contributors

lauzy avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.