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

Viewed 1042

I want to have 2 grid images one vertical and second horizontal(recyclerview1 and recyclerview2), the first I want it to be always top and to be scrolled right and left, however when I scroll the second grid view , I want the first to be scrolled too as they are in one scroller

example:

enter image description here

when I scroll down in the second recyclerview (recyclerview2) , i want the first recycler to be scrolled too. How to do that ? result:

enter image description here

this is my 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>
2 Answers
Related