Created
February 18, 2016 08:07
-
-
Save talklittle/9c05375c10fafe1c2388 to your computer and use it in GitHub Desktop.
recycler-fast-scroll issue 8 https://github.com/FutureMind/recycler-fast-scroll/issues/8
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
<?xml version="1.0" encoding="utf-8"?> | |
<android.support.design.widget.CoordinatorLayout | |
xmlns:android="http://schemas.android.com/apk/res/android" | |
xmlns:app="http://schemas.android.com/apk/res-auto" | |
xmlns:tools="http://schemas.android.com/tools" | |
android:layout_width="match_parent" | |
android:layout_height="match_parent" | |
android:fitsSystemWindows="true" | |
tools:context="com.talklittle.recyclerfastscrollgithubissue8.MainActivity"> | |
<android.support.design.widget.AppBarLayout | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:theme="@style/AppTheme.AppBarOverlay"> | |
<android.support.v7.widget.Toolbar | |
android:id="@+id/toolbar" | |
android:layout_width="match_parent" | |
android:layout_height="?attr/actionBarSize" | |
android:background="?attr/colorPrimary" | |
app:popupTheme="@style/AppTheme.PopupOverlay"/> | |
</android.support.design.widget.AppBarLayout> | |
<include layout="@layout/content_main"/> | |
<android.support.design.widget.FloatingActionButton | |
android:id="@+id/fab" | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:layout_gravity="bottom|end" | |
android:layout_margin="@dimen/fab_margin" | |
android:src="@android:drawable/ic_dialog_email"/> | |
</android.support.design.widget.CoordinatorLayout> |
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
<?xml version="1.0" encoding="utf-8"?> | |
<RelativeLayout | |
xmlns:android="http://schemas.android.com/apk/res/android" | |
xmlns:app="http://schemas.android.com/apk/res-auto" | |
xmlns:tools="http://schemas.android.com/tools" | |
android:layout_width="match_parent" | |
android:layout_height="match_parent" | |
android:paddingBottom="@dimen/activity_vertical_margin" | |
android:paddingLeft="@dimen/activity_horizontal_margin" | |
android:paddingRight="@dimen/activity_horizontal_margin" | |
android:paddingTop="@dimen/activity_vertical_margin" | |
app:layout_behavior="@string/appbar_scrolling_view_behavior" | |
tools:context="com.talklittle.recyclerfastscrollgithubissue8.MainActivity" | |
tools:showIn="@layout/activity_main"> | |
<android.support.v7.widget.RecyclerView | |
android:id="@+id/recyclerview" | |
android:layout_width="match_parent" | |
android:layout_height="match_parent"/> | |
<com.futuremind.recyclerviewfastscroll.FastScroller | |
android:id="@+id/fastscroller" | |
android:orientation="vertical" | |
android:layout_width="wrap_content" | |
android:layout_height="match_parent" | |
android:layout_alignParentRight="true"/> | |
</RelativeLayout> |
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
package com.talklittle.recyclerfastscrollgithubissue8; | |
import android.os.Bundle; | |
import android.support.design.widget.FloatingActionButton; | |
import android.support.v7.app.AppCompatActivity; | |
import android.support.v7.widget.LinearLayoutManager; | |
import android.support.v7.widget.RecyclerView; | |
import android.support.v7.widget.Toolbar; | |
import android.view.Menu; | |
import android.view.MenuItem; | |
import android.view.View; | |
import android.view.ViewGroup; | |
import android.widget.TextView; | |
import com.futuremind.recyclerviewfastscroll.FastScroller; | |
public class MainActivity extends AppCompatActivity { | |
private FastScroller mFastScroller; | |
private RecyclerView mRecyclerView; | |
private int mItemCount; | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_main); | |
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); | |
setSupportActionBar(toolbar); | |
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab); | |
fab.setOnClickListener(new View.OnClickListener() { | |
@Override | |
public void onClick(View view) { | |
toggleItemCount(); | |
} | |
}); | |
mRecyclerView = (RecyclerView) findViewById(R.id.recyclerview); | |
mFastScroller = (FastScroller) findViewById(R.id.fastscroller); | |
mRecyclerView.setAdapter(new RecyclerView.Adapter() { | |
@Override | |
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { | |
TextView root = new TextView(MainActivity.this); | |
root.setText("hi fast scroller"); | |
return new DummyViewHolder(root); | |
} | |
@Override | |
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) { | |
} | |
@Override | |
public int getItemCount() { | |
return mItemCount; | |
} | |
}); | |
mRecyclerView.setLayoutManager(new LinearLayoutManager(this)); | |
mRecyclerView.setItemAnimator(null); | |
mFastScroller.setRecyclerView(mRecyclerView); | |
} | |
private void toggleItemCount() { | |
final int maxCount = 40; | |
mItemCount = mItemCount == 0 ? maxCount : 0; | |
if (mItemCount == 0) { | |
mRecyclerView.getAdapter().notifyItemRangeRemoved(0, maxCount); | |
mRecyclerView.post(new Runnable() { | |
@Override | |
public void run() { | |
mRecyclerView.requestLayout(); | |
} | |
}); | |
} else { | |
mRecyclerView.getAdapter().notifyItemRangeInserted(0, maxCount); | |
} | |
} | |
@Override | |
public boolean onCreateOptionsMenu(Menu menu) { | |
// Inflate the menu; this adds items to the action bar if it is present. | |
getMenuInflater().inflate(R.menu.menu_main, menu); | |
return true; | |
} | |
@Override | |
public boolean onOptionsItemSelected(MenuItem item) { | |
// Handle action bar item clicks here. The action bar will | |
// automatically handle clicks on the Home/Up button, so long | |
// as you specify a parent activity in AndroidManifest.xml. | |
int id = item.getItemId(); | |
//noinspection SimplifiableIfStatement | |
if (id == R.id.action_settings) { | |
return true; | |
} | |
return super.onOptionsItemSelected(item); | |
} | |
@Override | |
protected void onPostResume() { | |
super.onPostResume(); | |
toggleItemCount(); | |
} | |
private class DummyViewHolder extends RecyclerView.ViewHolder { | |
public DummyViewHolder(View itemView) { | |
super(itemView); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment