Advertisement
Guest User

Untitled

a guest
Mar 28th, 2017
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.55 KB | None | 0 0
  1. <android.support.design.widget.CoordinatorLayout
  2. xmlns:android="http://schemas.android.com/apk/res/android"
  3. xmlns:app="http://schemas.android.com/apk/res-auto"
  4. android:layout_width="match_parent"
  5. android:layout_height="match_parent">
  6.  
  7. <LinearLayout
  8. android:layout_width="match_parent"
  9. android:layout_height="match_parent"
  10. android:orientation="vertical">
  11.  
  12. <FrameLayout
  13. android:id="@+id/container_sheet"
  14. android:layout_width="match_parent"
  15. android:layout_height="0dp"
  16. android:layout_weight="1">
  17.  
  18. <LinearLayout
  19. android:layout_width="match_parent"
  20. android:orientation="vertical"
  21. android:layout_height="match_parent">
  22.  
  23. <android.support.v7.widget.Toolbar
  24. android:id="@+id/toolbar"
  25. app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
  26. android:layout_width="match_parent"
  27. android:layout_height="?android:actionBarSize"
  28. android:background="@color/toolbar_bg"/>
  29.  
  30. <android.support.v4.widget.SwipeRefreshLayout
  31. android:id="@+id/swiper"
  32. android:layout_width="match_parent"
  33. android:layout_height="match_parent">
  34.  
  35. <android.support.v7.widget.RecyclerView
  36. android:layout_width="match_parent"
  37. android:layout_marginLeft="10dp"
  38. android:layout_marginRight="10dp"
  39. android:layout_height="match_parent"
  40. android:id="@+id/audio_list"/>
  41.  
  42. </android.support.v4.widget.SwipeRefreshLayout>
  43.  
  44. </LinearLayout>
  45.  
  46. <include layout="@layout/music_sheet"/>
  47.  
  48. </FrameLayout>
  49.  
  50. <include layout="@layout/music_panel"/>
  51.  
  52. </LinearLayout>
  53.  
  54. <android.support.design.widget.FloatingActionButton
  55. android:id="@+id/sheet_door"
  56. android:visibility="gone"
  57. android:layout_width="wrap_content"
  58. android:layout_height="wrap_content"
  59. android:layout_margin="16dp"
  60. android:clickable="true"
  61. android:src="@drawable/fab"
  62. app:backgroundTint="#527dad"
  63. app:borderWidth="0dp"
  64. app:elevation="6dp"
  65. app:layout_behavior="com.lovemusic.bestmusiclife.FABScrollBehavior"
  66. app:fabSize="normal"
  67. app:layout_anchor="@id/container_sheet"
  68. app:layout_anchorGravity="bottom|right|end"/>
  69.  
  70. </android.support.design.widget.CoordinatorLayout>
  71.  
  72. public abstract class zScrollController extends RecyclerView.OnScrollListener {
  73. private int lastHold, allScroll;
  74. private boolean upTrackingBlocked, downTrackingBlocked;
  75.  
  76. @Override
  77. public final void onScrolled(RecyclerView recyclerView, int dx, int dy) {
  78. allScroll += dy;
  79. if (allScroll > lastHold + getThreshold()) {
  80. lastHold = allScroll;
  81. if (!downTrackingBlocked){
  82. downTrackingBlocked = true;
  83. upTrackingBlocked = false;
  84. onDownScrolled();
  85. }
  86. } else if (allScroll < lastHold - getThreshold()) {
  87. lastHold = allScroll;
  88. if (!upTrackingBlocked){
  89. upTrackingBlocked = true;
  90. downTrackingBlocked = false;
  91. onUpScrolled();
  92. }
  93. }
  94. }
  95.  
  96. @Override
  97. public final void onScrollStateChanged(RecyclerView recyclerView, int newState) {
  98. super.onScrollStateChanged(recyclerView, newState);
  99. }
  100.  
  101. /**
  102. * Default threshold for scrolling, value in pixels
  103. * */
  104. public static final int DEFAULT_THRESHOLD = 30;
  105.  
  106. /**
  107. * Big threshold for scrolling, value in pixels
  108. * */
  109. public static final int BIG_THRESHOLD = 50;
  110.  
  111. /**
  112. * Very big threshold for scrolling, value in pixels
  113. * */
  114. public static final int VERY_BIG_THRESHOLD = 100;
  115.  
  116. /**
  117. * Threshold for scrolling. By default have 30 px
  118. * */
  119. public int getThreshold() {
  120. return DEFAULT_THRESHOLD;
  121. }
  122.  
  123. public abstract void onUpScrolled();
  124. public abstract void onDownScrolled();
  125. }
  126.  
  127. ViewTreeObserver observer = panel.getViewTreeObserver();
  128. observer.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
  129. @Override
  130. public void onGlobalLayout() {
  131. int pahelHeight = panel.getHeight();
  132. recyclerView.addOnScrollListener(new zScrollController(){
  133. @Override
  134. public void onUpScrolled(){
  135. if (!fab.isShown()) fab.show();
  136. ViewCompat.animate(panel)/*тут ваша анимация*/.withEndAction(() -> recyclerView.setPadding(
  137. recyclerView.getPaddingLeft(),
  138. recyclerView.getPaddingTop(),
  139. recyclerView.getPaddingRight(),
  140. panelHeight
  141. ));
  142. }
  143. @Override
  144. public void onDownScrolled(){
  145. if (fab.isShown()) fab.hide();
  146. ViewCompat.animate(panel)/*тут ваша анимация*/.withStartAction(() -> recyclerView.setPadding(
  147. recyclerView.getPaddingLeft(),
  148. recyclerView.getPaddingTop(),
  149. recyclerView.getPaddingRight(),
  150. 0
  151. ));
  152. }
  153. @Override
  154. public int getThreshold() {
  155. return DEFAULT_THRESHOLD; //optional
  156. }
  157. });
  158. ViewTreeObserver observer = panel.getViewTreeObserver();
  159. if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {
  160. observer.removeGlobalOnLayoutListener(this);
  161. } else {
  162. observer.removeOnGlobalLayoutListener(this);
  163. }
  164. }
  165. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement