There is a fragment, in it recyclerView , consisting of the following markup:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" xmlns:app="http://schemas.android.com/apk/res-auto" android:id="@+id/recyclefragment" android:orientation="vertical"> <LinearLayout android:layout_width="match_parent" android:layout_height="48dp" android:background="#F0F0F0" android:id="@+id/subheader" android:orientation="vertical" android:clickable="false" android:padding="16dp"> <TextView android:paddingLeft="20dp" android:clickable="false" android:text="Очевидно длинный текст" android:textColor="#9e9e9e" android:textSize="14sp" android:layout_height="wrap_content" android:layout_width="wrap_content" /> </LinearLayout> <android.support.v7.widget.RecyclerView android:id="@+id/rvWords" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_below="@+id/subheader" android:layout_above="@+id/bottom_bar" /> <FrameLayout android:layout_width="match_parent" android:layout_height="56dp" android:layout_alignParentBottom="true" android:background="#757575" android:orientation="horizontal" android:id="@+id/bottom_bar" android:paddingLeft="64dp" android:paddingRight="64dp"> <ImageButton android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="start|center" android:layout_marginLeft="25dp" android:background="@android:color/transparent" android:src="@drawable/filter" android:text="button 1" /> <ImageButton android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" android:background="@android:color/transparent" android:src="@drawable/sort" android:text="button 2" /> <ImageButton android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="end|center" android:layout_marginRight="25dp" android:background="@android:color/transparent" android:src="@drawable/suggest_term" android:text="button 3" /> </FrameLayout> The problem is that you need to hide and show the subHeader when scrolling. I wrote a simple animation, everything works.
With only one unpleasant feature, namely, when it disappears, the ViewGroup leaves with TextView , and there remains empty space.
Okay, I thought, and supplemented my methods with the appearance and disappearance of the view . It looked like this:
private void hideView() { subheader.animate().translationY(-subheader.getHeight()).setInterpolator(new AccelerateInterpolator(2)); subheader.setVisibility(View.GONE); } private void showView() { subheader.animate().translationY(0).setInterpolator(new DecelerateInterpolator(2)).start(); subheader.setVisibility(View.VISIBLE); } rvContacts.setOnScrollListener(new HidingScrollSubheader() { @Override public void onHide() { hideView(); } @Override public void onShow() { showView(); } }); } However, as it scrolls, it starts to specifically pull in different directions, then showing, then hiding.
Scroll implementation:
public abstract class HidingScrollSubheader extends RecyclerView.OnScrollListener { private static final int HIDE_THRESHOLD = 15; private int scrolledDistance = 0; private boolean controlsVisible = true; @Override public void onScrolled(RecyclerView recyclerView, int dx, int dy) { super.onScrolled(recyclerView, dx, dy); if (scrolledDistance > HIDE_THRESHOLD && controlsVisible) { onHide(); controlsVisible = false; scrolledDistance = 0; } else if (scrolledDistance < -HIDE_THRESHOLD && !controlsVisible) { onShow(); controlsVisible = true; scrolledDistance = 0; } if ((controlsVisible && dy > 0) || (!controlsVisible && dy < 0)) { scrolledDistance += dy; } } public abstract void onHide(); public abstract void onShow(); } I understand that I was mistaken in some place, and I’m not hiding / showing a twist there, but I can’t find an error at close range.
Coordinator Layout, respectively, and the flags do not work. Tried - offer to wrap it? - SilentoCoordinatorLayoutwhy not use it? As for the flags, I did not understand what kind of flags? - xkorapp:layout_scrollFlags="scroll|enterAlwaysCollapsed"- Silento