android - Two recyclerview when i scroll down , the first recylcer to be scrolled too, how? -


i want have 2 grid images 1 vertical , second horizontal(recyclerview1 , recyclerview2), first want top , scrolled right , left, when scroll second grid view , want first scrolled in 1 scroller

example:

enter image description here

when scroll down in second recyclerview (recyclerview2) , want first recycler scrolled too. how ? result:

enter image description here

this code:

main activity code:

   protected void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         setcontentview(r.layout.activity_main);         toolbar toolbar = (toolbar) findviewbyid(r.id.toolbar);         setsupportactionbar(toolbar);        // inittoolbars();          recyclerview = (recyclerview) findviewbyid(r.id.recyclerview1);         recylerviewlayoutmanager = new linearlayoutmanager(context,linearlayoutmanager.horizontal,false);         recyclerview.setlayoutmanager(recylerviewlayoutmanager);         recyclerviewadapter = new recyclerviewadapter(mainactivity.this, subjects,images);         recyclerview.setadapter(recyclerviewadapter);           maingridrecview = (recyclerview) findviewbyid(r.id.maingridrc);         maingridrecviewlayoutmanager = new gridlayoutmanager(context,2);         maingridrecview.setlayoutmanager(maingridrecviewlayoutmanager);         maingridrecviewadapter = new maingridrecyclerviewadapter(mainactivity.this, subjects,images);         maingridrecview.setadapter(maingridrecviewadapter); 

activity xml:

<android.support.v4.widget.nestedscrollview     android:layout_width="match_parent"     android:layout_height="wrap_content">      <linearlayout xmlns:android="http://schemas.android.com/apk/res/android"     xmlns:app="http://schemas.android.com/apk/res-auto"     android:id="@+id/liner1"     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:orientation="vertical">      <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>       <textview         android:id="@+id/textview3"         android:layout_width="match_parent"         android:layout_height="25dp"         android:layout_above="@+id/recyclerview1"         android:gravity="center"         android:background="#10bcc9"         android:textcolor="@android:color/white"         android:text="new games." />      <android.support.v7.widget.recyclerview         android:id="@+id/recyclerview1"         android:layout_width="wrap_content"         android:layout_height="140dp"         android:scrollbars="horizontal" />      <textview         android:id="@+id/textview4"         android:layout_width="match_parent"         android:layout_height="25dp"         android:layout_below="@+id/recyclerview1"         android:gravity="center"         android:background="#10bcc9"         android:textcolor="@android:color/white"         android:text="used games." />      <android.support.v7.widget.recyclerview         android:id="@+id/maingridrc"         android:layout_width="wrap_content"         android:layout_height="330dp"         android:layout_margintop="5dp"         android:scrollbars="vertical" />    <!--  <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" />--> </linearlayout> 

adapter

public class recyclerviewadapter extends recyclerview.adapter<viewholder>{      string[] subjectvalues;     string[] imagevalues;     context mcontext;     view view1;     viewholder viewholder1;   // textview textview;      public recyclerviewadapter(context context,string[] subjectvalues1, string[] images){          subjectvalues = subjectvalues1;         imagevalues= images;         mcontext = context;     }      public static class viewholder extends recyclerview.viewholder{          public viewholder(view v){              super(v);          }     }      @override     public viewholder oncreateviewholder(viewgroup parent, int viewtype){          view1 = layoutinflater.from(parent.getcontext()).inflate(r.layout.recyclerview_items,parent,false);        //  viewholder1 = new viewholder(view1);          viewholder vh = new viewholder(view1, new viewholder.imyviewholderclicks() {             public void onpotato(view caller) { log.d("vegetables", "poh-tah-tos");                 intent intent = new intent(mcontext,singleobjectactivity.class);                 mcontext.startactivity(intent);             };             public void ontomato(imageview callerimage) {                 log.d("vegetables", "to-m8-tohs");                  //  v1    categorylist mdataset = new categorylist(getorder(), getid(), item.geturl(), item.getusername(), item.getlikes());                  intent intent = new intent(mcontext,singleobjectactivity.class);                 mcontext.startactivity(intent);             }         });          return vh;     }      @override     public void onbindviewholder(viewholder holder, int position){          holder.txtviewtitle.settext(subjectvalues[position]);         holder.imgviewicon.setimageresource(r.drawable.ghost_recon);     }      @override     public int getitemcount(){          return subjectvalues.length;     } } 

recycler xml

<relativelayout xmlns:android="http://schemas.android.com/apk/res/android"     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:orientation="horizontal">      <imageview         android:id="@+id/imagecateg"         android:layout_width="180dp"         android:layout_height="160dp"         android:layout_alignparenttop="true"         />      <textview         android:id="@+id/txtview"         android:layout_width="200dp"         android:layout_height="wrap_content"         android:layout_below="@+id/imagecateg"         android:paddingleft="35dp"         android:textsize="15dp"         android:textstyle="bold"         android:background="#f4e04c"         android:textcolor="@color/colorprimary"         />     </relativelayout> 

if want scroll entire layout when 2nd recycler view being scrolled -> can add first recycler view 1st item of second recycler view, in case behave 1 recycler view.

i able implement quick example, code not brilliant, reflecting general idea, pushed github

here main file logic in first recyclerview adapter.


Comments

Popular posts from this blog

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

python Tkinter Capturing keyboard events save as one single string -

sql server - Why does Linq-to-SQL add unnecessary COUNT()? -