实现Material滚动技术的Android库:material-scrolling

cw63 10年前

实现Material滚动技术的Android库 material scrolling techniques.

ViewPager ImageFab

特性

用法

(For a working implementation of this project see the sample.)

MaterialScrollingLayout

LayoutObservableRecyclerViewinside ofMaterialScrollingLayout.

<jp.satorufujiwara.scrolling.MaterialScrollingLayout          xmlns:android="http://schemas.android.com/apk/res/android"          xmlns:app="http://schemas.android.com/apk/res-auto"          android:id="@+id/materialScrollingLayout"          android:layout_width="match_parent"          android:layout_height="match_parent"          app:ms_flexible_height="240dp"          >        <com.github.ksoichiro.android.observablescrollview.ObservableRecyclerView              android:id="@+id/recyclerView"              android:layout_width="match_parent"              android:layout_height="match_parent"              />    </jp.satorufujiwara.scrolling.MaterialScrollingLayout>

ms_flexible_heightis height fromRecyclerViews top toRecyclerView's first item.

And callMaterialScrollingLayout.addBehavior(View, Behavior)in Activity or Fragment.

First argument is targetView. Second argument isView's behavior while scrolling.

materialScrollingLayout.addBehavior(bgImageView, new ParallaxBehavior());  materialScrollingLayout.addBehavior(titleTextView, new ScrollingBehavior());  materialScrollingLayout.addBehavior(fabView, new FabBehavior(getResources()));

FabBehavioris customizedBehavior. If you want customize behavior, create class that extends 'Behavior'.

public class TitleBehavior extends Behavior {        private final int scrollLimitHeight;        public TitleBehavior(Resources r) {          scrollLimitHeight = r.getDimensionPixelOffset(R.dimen.title_scroll_height);      }        @Override      protected void onScrolled(View target, int scrollY, int dy) {          ViewCompat.setTranslationY(target, -Math.min(scrollY, scrollLimitHeight));      }  }

项目主页:http://www.open-open.com/lib/view/home/1443236387216