in my Project I want to have two Recyclerview
(first one Horizontal and second Vertical)
if I scroll screen (vertically) I want both of them scroll together.
i tryed some way but not worked please help me
my xml of fragment
<?xml version="1.0" encoding="utf-8"?>
<ScrollView 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"
tools:context=".Fragments.Tabs.FarsiF.FarsiBadr">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerview_id_Horizental_badr_farsi"
android:layout_width="match_parent"
android:layout_height="wrap_content"></android.support.v7.widget.RecyclerView>
<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerview_id_vertical_badr_farsi"
android:layout_width="match_parent"
android:layout_height="match_parent">
</android.support.v7.widget.RecyclerView>
</LinearLayout>
</ScrollView>
my class of fragment
public class FarsiBadr extends Fragment {
RecyclerViewAdapter myAdapter;
List<Items> lstItems;
public FarsiBadr() {
// Required empty public constructor
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) {
// Inflate the layout for this fragment
View view = inflater.inflate(R.layout.fragment_farsi_badr, container, false);
lstItems = new ArrayList<>();
lstItems.add(new Items("1 Tv", "11111", "77777", "horizental", R.drawable.gemtv));
lstItems.add(new Items("2 Tv", "22222", "88888", "horizental", R.drawable.bbc));
lstItems.add(new Items("3 Tv", "33333", "99999", "horizental", R.drawable.voa));
lstItems.add(new Items("4 Tv", "44444", "44444", "horizental", R.drawable.manoto));
//horizontal recycler view
RecyclerView myrv = view.findViewById(R.id.recyclerview_id_Horizental_badr_farsi);
myAdapter = new RecyclerViewAdapter(getContext(), lstItems);
myrv.setLayoutManager(new LinearLayoutManager(getContext(), LinearLayoutManager.HORIZONTAL, false));
myrv.setAdapter(myAdapter);
//vertical mode
RecyclerView verticalmode = view.findViewById(R.id.recyclerview_id_vertical_badr_farsi);
myAdapter = new RecyclerViewAdapter(getContext(), lstItems);
verticalmode.setLayoutManager(new GridLayoutManager(getContext(), 3));
verticalmode.setAdapter(myAdapter);
return view;
}
}
just by changing scrollview
to <android.support.v4.widget.NestedScrollView
you can solve your problem
try this
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.NestedScrollView 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"
tools:context=".multi.TabFragment">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<EditText
android:id="@+id/searchintabbadrkurdi"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerview_id_badr_kurdish_hor"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</android.support.v7.widget.RecyclerView>
<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerview_id_badr_kurdish"
android:layout_width="match_parent"
android:layout_height="match_parent">
</android.support.v7.widget.RecyclerView>
</LinearLayout>
</android.support.v4.widget.NestedScrollView>