Skip to content

Instantly share code, notes, and snippets.

@mzgreen
mzgreen / PartThreeFragment.java
Created June 23, 2015 10:50
HideOnScrollExample - PartThreeFragment
public class PartThreeFragment extends Fragment {
public final static String ITEMS_COUNT_KEY = "PartThreeFragment$ItemsCount";
public static PartThreeFragment createInstance(int itemsCount) {
PartThreeFragment partThreeFragment = new PartThreeFragment();
Bundle bundle = new Bundle();
bundle.putInt(ITEMS_COUNT_KEY, itemsCount);
partThreeFragment.setArguments(bundle);
return partThreeFragment;
@mzgreen
mzgreen / fragment_part_three.xml
Created June 23, 2015 10:48
HideOnScrollExample - fragment_part_three layout
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.RecyclerView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
@mzgreen
mzgreen / build.gradle
Created June 23, 2015 10:38
HideOnScrollExample - build file
android {
compileSdkVersion 22
buildToolsVersion "22.0.1"
defaultConfig {
minSdkVersion 14
targetSdkVersion 22
}
}
@mzgreen
mzgreen / PartTwoActivity.java
Last active August 29, 2015 14:16
PartTwoActivity class setting GridLayoutManager
private void initRecyclerView() {
final RecyclerView recyclerView = (RecyclerView) findViewById(R.id.recyclerView);
int paddingTop = Utils.getToolbarHeight(PartTwoActivity.this) + Utils.getTabsHeight(PartTwoActivity.this);
recyclerView.setPadding(recyclerView.getPaddingLeft(), paddingTop, recyclerView.getPaddingRight(), recyclerView.getPaddingBottom());
recyclerView.setLayoutManager(new GridLayoutManager(this, 3));
RecyclerAdapter recyclerAdapter = new RecyclerAdapter(createItemList());
//...
@mzgreen
mzgreen / HidingScrollListener.java
Created February 28, 2015 08:36
HidingScrollListener class with fixed top position hiding
public abstract class HidingScrollListener extends RecyclerView.OnScrollListener {
private static final float HIDE_THRESHOLD = 10;
private static final float SHOW_THRESHOLD = 70;
private int mToolbarOffset = 0;
private boolean mControlsVisible = true;
private int mToolbarHeight;
private int mTotalScrolledDistance;
@mzgreen
mzgreen / part_two_activity.xml
Created February 28, 2015 08:34
PartTwoActivity class layout file
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipToPadding="false"/>
@mzgreen
mzgreen / PartTwoActivity.java
Created February 28, 2015 08:32
PartTwoActivity class with tabs
public class PartTwoActivity extends ActionBarActivity {
private LinearLayout mToolbarContainer;
private int mToolbarHeight;
@Override
protected void onCreate(Bundle savedInstanceState) {
setTheme(R.style.AppThemeGreen);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_part_two);
@mzgreen
mzgreen / PartTwoActivity.java
Created February 28, 2015 08:31
PartTwoActivity setting padding on RecyclerView
private void initRecyclerView() {
final RecyclerView recyclerView = (RecyclerView) findViewById(R.id.recyclerView);
int paddingTop = Utils.getToolbarHeight(PartTwoActivity.this) + Utils.getTabsHeight(PartTwoActivity.this);
recyclerView.setPadding(recyclerView.getPaddingLeft(), paddingTop, recyclerView.getPaddingRight(), recyclerView.getPaddingBottom());
recyclerView.setLayoutManager(new LinearLayoutManager(this));
// ...
}
@mzgreen
mzgreen / tabs.xml
Created February 28, 2015 08:28
Tabs layout file
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="@dimen/tabsHeight"
android:background="?attr/colorPrimary">
<FrameLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1" >
<TextView
android:layout_width="match_parent"
@mzgreen
mzgreen / part_two_activity.xml
Last active August 29, 2015 14:16
PartTwoActivity layout with tabs
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipToPadding="false"/>