Git Product home page Git Product logo

lbehavior's Introduction

LBehavior: Simple implementation of sliding animation of title bar, bottom bar and floatingActionButton.

中文文档

ScreenShoot

screenshot screenshot screenshot

Blog Introduce

JianShu: http://www.jianshu.com/p/2974d8ffc3a5

Personal WebSite: http://blog.lauzy.me/2017/04/14/201705Behavior/

Download

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

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

The version code of the latest release can be found here

Usage

Xml file:

The root layout must be CoordinatorLayout,which is similar to FrameLayout

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

Set different layout_behavior in xml file according to different view.

Param Explanation
@string/title_view_behavior TitleBar
@string/bottom_view_behavior BottomBar
@string/fab_scale_behavior FloatingActionButton(scale anim)
@string/fab_vertical_behavior FloatingActionButton(slide anim)

Custom properties(All have default values):

Function Param Explanation
setMinScrollY int y Sets the minimum sliding distance for triggering the animation. The default value is 5 pixels.
setScrollYDistance int y Sets the sliding distance for triggering the animation. The animation can be triggered when the total sliding distance is greater than this property, even if the single sliding distance is less than the minimum distance. The default value is 40 pixels.
setDuration int duration Sets the length of the animation. The default value is 400 milliseconds.
setInterpolator Interpolator interpolator Sets the interpolator to be used by this animation.The default interpolator is LinearOutSlowInInterpolator. Interpolator official documentation
	CommonBehavior.from(mFloatingActionButton).show();//show the view
	CommonBehavior.from(mFloatingActionButton).hide();//hide

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

Tips

1、Because the root layout is CoordinatorLayout, the toolbar may cover the item at the top of the recyclerView when used, and the bottom bar may also cover the bottom item. You can add a placeholder such as itemDecoration to the recyclerView, or a placeholder view at the top. If the situation is relatively simple, you can simply set padding, margin and so on. I have dealt with this kind of situation in the demo simply.

2、If the elevation of the floatingActionButton is greater than that of the bottomBar, the animation of the floatingActionButton will cover the top of the bottomBar, and vice versa.

Apk and More Info

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

License

Copyright 2017 Lauzy

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

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.