This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private void hideViews() { | |
mToolbar.animate().translationY(-mToolbar.getHeight()).setInterpolator(new AccelerateInterpolator(2)); | |
FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) mFabButton.getLayoutParams(); | |
int fabBottomMargin = lp.bottomMargin; | |
mFabButton.animate().translationY(mFabButton.getHeight()+fabBottomMargin).setInterpolator(new AccelerateInterpolator(2)).start(); | |
} | |
private void showViews() { | |
mToolbar.animate().translationY(0).setInterpolator(new DecelerateInterpolator(2)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private void initRecyclerView() { | |
RecyclerView recyclerView = (RecyclerView) findViewById(R.id.recyclerView); | |
recyclerView.setLayoutManager(new LinearLayoutManager(this)); | |
RecyclerAdapter recyclerAdapter = new RecyclerAdapter(createItemList()); | |
recyclerView.setAdapter(recyclerAdapter); | |
//setting up our OnScrollListener | |
recyclerView.setOnScrollListener(new HidingScrollListener() { | |
@Override | |
public void onHide() { | |
hideViews(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if (scrolledDistance > HIDE_THRESHOLD && controlsVisible) { | |
onHide(); | |
controlsVisible = false; | |
scrolledDistance = 0; | |
} else if (scrolledDistance < -HIDE_THRESHOLD && !controlsVisible) { | |
onShow(); | |
controlsVisible = true; | |
scrolledDistance = 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if((controlsVisible && dy>0) || (!controlsVisible && dy<0)) { | |
scrolledDistance += dy; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public abstract class HidingScrollListener extends RecyclerView.OnScrollListener { | |
private static final int HIDE_THRESHOLD = 20; | |
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) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class RecyclerHeaderViewHolder extends RecyclerView.ViewHolder { | |
public RecyclerHeaderViewHolder(View itemView) { | |
super(itemView); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<View xmlns:android="http://schemas.android.com/apk/res/android" | |
android:layout_width="match_parent" | |
android:layout_height="?attr/actionBarSize"/> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class RecyclerAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> { | |
//added view types | |
private static final int TYPE_HEADER = 2; | |
private static final int TYPE_ITEM = 1; | |
private List<String> mItemList; | |
public RecyclerAdapter(List<String> itemList) { | |
mItemList = itemList; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<android.support.v7.widget.RecyclerView | |
android:id="@+id/recyclerView" | |
android:layout_width="match_parent" | |
android:layout_height="match_parent" | |
android:paddingTop="?attr/actionBarSize" | |
android:clipToPadding="false"/> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class RecyclerAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> { | |
private List<String> mItemList; | |
public RecyclerAdapter(List<String> itemList) { | |
mItemList = itemList; | |
} | |
@Override | |
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { | |
final View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.recycler_item, parent, false); |