Android alphabetical fast scrollview in RecyclerView with Collapsing toolbar -


in application have activity_main.xml this:-

<coordinator layout>    <appbarlayout>       <collapsingtoolbarlayout>            <imageview/>            <toolbar/>        </collapsingtoolbarlayout>    </appbarlayout>    <recyclerview/> </coordinating layout> 

layout.xml ----->>>

<?xml version="1.0" encoding="utf-8"?>    <android.support.v4.widget.drawerlayout xmlns:android="http://schemas.android.com/apk/res/android"     xmlns:tools="http://schemas.android.com/tools"     xmlns:ads="http://schemas.android.com/apk/res-auto"     android:layout_width="match_parent"     android:layout_height="match_parent"     android:background="@drawable/theme_background"     android:id="@+id/drawerlayout"     >       <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"         android:id="@+id/activity_main_id"         tools:context="objectdistance.ajai.ram.sita.gallery.mainactivity">          <android.support.design.widget.appbarlayout             android:id="@+id/app_bar_layout"             android:layout_width="match_parent"             android:layout_height="wrap_content"             android:fitssystemwindows="true"             android:theme="@style/themeoverlay.appcompat.dark.actionbar">               <android.support.design.widget.collapsingtoolbarlayout                 android:id="@+id/collapsing_toolbar"                 android:layout_width="match_parent"                 android:layout_height="match_parent"                 app:layout_scrollflags="scroll|exituntilcollapsed"                 app:contentscrim="?attr/colorprimary"                 app:expandedtitlemarginstart="48dp"                 app:expandedtitlemarginend="64dp"                 android:fitssystemwindows="true">                    <imageview                     android:id="@+id/imagetoolbar"                     android:layout_width="match_parent"                     android:layout_height="200dp"                     android:scaletype="centercrop"                     android:fitssystemwindows="true"                     android:foreground="@drawable/image_header_foreground"                     app:layout_scrollflags="scroll"                     app:layout_collapsemode="parallax"/>                  <android.support.v7.widget.toolbar                     android:id="@+id/toolbar"                     android:layout_width="match_parent"                     android:layout_height="?attr/actionbarsize"                     app:popuptheme="@style/themeoverlay.appcompat.light"                     android:background="@drawable/theme_background"                     app:layout_collapsemode="pin" >                      <spinner                         android:id="@+id/spinner_nav"                         android:layout_width="wrap_content"                         android:layout_height="wrap_content"                          android:dropdownverticaloffset="?attr/actionbarsize" />                  </android.support.v7.widget.toolbar>              </android.support.design.widget.collapsingtoolbarlayout>           </android.support.design.widget.appbarlayout>             <android.support.v7.widget.recyclerview             android:id="@+id/list"             android:layout_width="match_parent"             android:layout_height="match_parent"             app:layout_behavior="@string/appbar_scrolling_view_behavior" />         </android.support.design.widget.coordinatorlayout>       <listview         android:layout_width="200dp"         android:layout_height="match_parent"         android:id="@+id/navlist"         android:background="#dedede"         android:layout_gravity="start" />  </android.support.v4.widget.drawerlayout> 

now want include fast scrolling recyclerview such image date can popup on scrolling.

sample image of such scrollbar:- scrolling

i searched , tried using few libraries think due collapsing toolbar scrollbar not working properly.

screenshot of scroll library used:- my device

here in case scroll bar starting top , scroll computation not proper.

please solving issue.

thanks

we want some knowledge of sectionindexer. here doc of sectionindexer.

we have set true setfastscrollenabled(true) method, used listview.......you can use recyclerview instead of listview in below example....

this activity

public class fastscoll extends listactivity {      listview fruitview;      @override     public void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         setcontentview(r.layout.activity_fast_scoll);          fruitview = (listview) findviewbyid(android.r.id.list);          fruitview.setfastscrollenabled(true);         string[] fruits = getresources().getstringarray(r.array.fruits_array);          final list<string> fruitlist = arrays.aslist(fruits);         collections.sort(fruitlist);         setlistadapter(new listadapter(this, fruitlist));          fruitview.setonitemclicklistener(new adapterview.onitemclicklistener() {              public void onitemclick(adapterview<?> parent, view arg1,                                     int position, long arg3) {                 log.e("sushildlh",fruitlist.get(position));             }         });      } } 

this activity_fast_scoll.xml file

<relativelayout xmlns:android="http://schemas.android.com/apk/res/android"     xmlns:tools="http://schemas.android.com/tools"     android:layout_width="match_parent"     android:layout_height="match_parent"     android:padding="5dp" >      <listview         android:id="@android:id/list"         android:layout_width="fill_parent"         android:layout_height="fill_parent"         android:scrollbarstyle="outsideoverlay" />  </relativelayout> 

and custom adapter sectionindexer....

public class listadapter extends arrayadapter<string> implements sectionindexer {      string[] sections;     list<string> fruits;     list<string> sectionletters=new arraylist<string>();      public listadapter(context context, list<string> fruitlist) {         super(context, android.r.layout.simple_list_item_1, fruitlist);         this.fruits = fruitlist;          (int x = 0; x < fruits.size(); x++) {             string fruit = fruits.get(x);             string ch = fruit.charat(0)+"";             ch = ch.touppercase(locale.us);              sectionletters.add(ch);         }          arraylist<string> sectionlist = new arraylist<string>(sectionletters);          sections = new string[sectionlist.size()];          sectionlist.toarray(sections);     }      public int getpositionforsection(int section) {          log.e("sushildlh", "" + section);         return section;     }      public int getsectionforposition(int position) {          log.d("sushildlh", "" + position);         return position;     }      public object[] getsections() {         return sections;     } } 

this fruits array in string.xml file.

 <string-array name="fruits_array">             <item>apples</item>             <item>apricots</item>             <item>avocado</item>             <item>annona</item>             <item>banana</item>             <item>bilberry</item>             <item>blackberry</item>             <item>custard apple</item>             <item>clementine</item>             <item>cantalope</item>             <item>coconut</item>             <item>currant</item>             <item>cherry</item>             <item>cherimoya</item>             <item>date</item>             <item>damson</item>             <item>durian</item>             <item>elderberry</item>             <item>fig</item>             <item>feijoa</item>             <item>grapefruit</item>             <item>grape</item>             <item>gooseberry</item>             <item>guava</item>             <item>honeydew melon</item>             <item>huckleberry</item>             <item>jackfruit</item>             <item>juniper berry</item>             <item>jambul</item>             <item>jujube</item>             <item>kiwi</item>             <item>kumquat</item>             <item>lemons</item>             <item>limes</item>             <item>lychee</item>             <item>mango</item>             <item>mandarin</item>             <item>mangostine</item>             <item>nectaraine</item>             <item>orange</item>             <item>olive</item>             <item>prunes</item>             <item>pears</item>             <item>plum</item>             <item>pineapple</item>             <item>peach</item>             <item>papaya</item>             <item>passionfruit</item>             <item>pomegranate</item>             <item>pomelo</item>             <item>raspberries</item>             <item>rock melon</item>             <item>rambutan</item>             <item>strawberries</item>             <item>sweety</item>             <item>salmonberry</item>             <item>satsuma</item>             <item>tangerines</item>             <item>tomato</item>             <item>ugli</item>             <item>watermelon</item>             <item>woodapple</item>         </string-array> 

and output of these code....

oo1o2

feel free ask if stuck anywhere in between code ....

note:- fastscroll image differ in different version of android (eg:-lollipop,marshmallow,etc) below output lollipop

lollipop

for custom alphabetical fast scrollview add these 2 line in style.xml file in apptheme.

<item name="android:fastscrolltextcolor">@color/apptheme_color</item>         //this used color of alphabetical fast scrollview <item name="android:fastscrollpreviewbackgroundright">@drawable/bg_default_focused_holo_light</item>          //this image or , drawable file want set on alphabetical fast scrollview 

custom fast scorll output :-

ouy


Comments