Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <android.support.design.widget.CoordinatorLayout
- 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">
- <LinearLayout
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:orientation="vertical">
- <FrameLayout
- android:id="@+id/container_sheet"
- android:layout_width="match_parent"
- android:layout_height="0dp"
- android:layout_weight="1">
- <LinearLayout
- android:layout_width="match_parent"
- android:orientation="vertical"
- android:layout_height="match_parent">
- <android.support.v7.widget.Toolbar
- android:id="@+id/toolbar"
- app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
- android:layout_width="match_parent"
- android:layout_height="?android:actionBarSize"
- android:background="@color/toolbar_bg"/>
- <android.support.v4.widget.SwipeRefreshLayout
- android:id="@+id/swiper"
- android:layout_width="match_parent"
- android:layout_height="match_parent">
- <android.support.v7.widget.RecyclerView
- android:layout_width="match_parent"
- android:layout_marginLeft="10dp"
- android:layout_marginRight="10dp"
- android:layout_height="match_parent"
- android:id="@+id/audio_list"/>
- </android.support.v4.widget.SwipeRefreshLayout>
- </LinearLayout>
- <include layout="@layout/music_sheet"/>
- </FrameLayout>
- <include layout="@layout/music_panel"/>
- </LinearLayout>
- <android.support.design.widget.FloatingActionButton
- android:id="@+id/sheet_door"
- android:visibility="gone"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_margin="16dp"
- android:clickable="true"
- android:src="@drawable/fab"
- app:backgroundTint="#527dad"
- app:borderWidth="0dp"
- app:elevation="6dp"
- app:layout_behavior="com.lovemusic.bestmusiclife.FABScrollBehavior"
- app:fabSize="normal"
- app:layout_anchor="@id/container_sheet"
- app:layout_anchorGravity="bottom|right|end"/>
- </android.support.design.widget.CoordinatorLayout>
- public abstract class zScrollController extends RecyclerView.OnScrollListener {
- private int lastHold, allScroll;
- private boolean upTrackingBlocked, downTrackingBlocked;
- @Override
- public final void onScrolled(RecyclerView recyclerView, int dx, int dy) {
- allScroll += dy;
- if (allScroll > lastHold + getThreshold()) {
- lastHold = allScroll;
- if (!downTrackingBlocked){
- downTrackingBlocked = true;
- upTrackingBlocked = false;
- onDownScrolled();
- }
- } else if (allScroll < lastHold - getThreshold()) {
- lastHold = allScroll;
- if (!upTrackingBlocked){
- upTrackingBlocked = true;
- downTrackingBlocked = false;
- onUpScrolled();
- }
- }
- }
- @Override
- public final void onScrollStateChanged(RecyclerView recyclerView, int newState) {
- super.onScrollStateChanged(recyclerView, newState);
- }
- /**
- * Default threshold for scrolling, value in pixels
- * */
- public static final int DEFAULT_THRESHOLD = 30;
- /**
- * Big threshold for scrolling, value in pixels
- * */
- public static final int BIG_THRESHOLD = 50;
- /**
- * Very big threshold for scrolling, value in pixels
- * */
- public static final int VERY_BIG_THRESHOLD = 100;
- /**
- * Threshold for scrolling. By default have 30 px
- * */
- public int getThreshold() {
- return DEFAULT_THRESHOLD;
- }
- public abstract void onUpScrolled();
- public abstract void onDownScrolled();
- }
- ViewTreeObserver observer = panel.getViewTreeObserver();
- observer.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
- @Override
- public void onGlobalLayout() {
- int pahelHeight = panel.getHeight();
- recyclerView.addOnScrollListener(new zScrollController(){
- @Override
- public void onUpScrolled(){
- if (!fab.isShown()) fab.show();
- ViewCompat.animate(panel)/*тут ваша анимация*/.withEndAction(() -> recyclerView.setPadding(
- recyclerView.getPaddingLeft(),
- recyclerView.getPaddingTop(),
- recyclerView.getPaddingRight(),
- panelHeight
- ));
- }
- @Override
- public void onDownScrolled(){
- if (fab.isShown()) fab.hide();
- ViewCompat.animate(panel)/*тут ваша анимация*/.withStartAction(() -> recyclerView.setPadding(
- recyclerView.getPaddingLeft(),
- recyclerView.getPaddingTop(),
- recyclerView.getPaddingRight(),
- 0
- ));
- }
- @Override
- public int getThreshold() {
- return DEFAULT_THRESHOLD; //optional
- }
- });
- ViewTreeObserver observer = panel.getViewTreeObserver();
- if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {
- observer.removeGlobalOnLayoutListener(this);
- } else {
- observer.removeOnGlobalLayoutListener(this);
- }
- }
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement