gpt4 book ai didi

java - 垂直 recyclerView 和水平 recyclerview 一起滚动

转载 作者:行者123 更新时间:2023-12-02 01:40:21 25 4
gpt4 key购买 nike

在我的项目中,我想要两个Recyclerview(第一个是水平的,第二个是垂直的)如果我(垂直)滚动屏幕,我希望它们一起滚动。

recyclerview scroll

我尝试了一些方法,但没有成功,请帮助我

我的片段 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你可以解决你的问题

试试这个

<?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>

关于java - 垂直 recyclerView 和水平 recyclerview 一起滚动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54532894/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com