垂直recyclerView和水平recyclerview一起滚动 [英] vertical recyclerView and Horizontal recyclerview scrolling together
本文介绍了垂直recyclerView和水平recyclerview一起滚动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在我的项目中,我想有两个Recyclerview
(第一个为水平,第二个为垂直)
如果我垂直滚动屏幕,我希望它们都一起滚动.
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
我的片段xml
<?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>
我的片段类
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;
}
}
推荐答案
只需将scrollview
更改为<android.support.v4.widget.NestedScrollView
你可以解决你的问题
just by changing scrollview
to <android.support.v4.widget.NestedScrollView
you can solve your problem
尝试
<?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>
这篇关于垂直recyclerView和水平recyclerview一起滚动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文