如何在 recyclerview 中启用 gridview 的滚动?
How to enable scrolling of grideview inside a recyclerview?
我有一个回收视图,这个回收视图的项目是这样的:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/question_bkg"
android:orientation="vertical"
>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/questionTitle"
android:padding="10dp"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:id="@+id/dynamicLayout"
android:layout_below="@id/questionTitle"
android:layout_alignParentLeft="true"></LinearLayout>
<GridView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@id/dynamicLayout"
android:numColumns="2"
android:id="@+id/questionChoicesRecycler"></GridView>
</RelativeLayout>
当我设置 recyclerView.setNestedScrollingEnabled(true);
但我仍然无法在 gridview 中滚动。我怎样才能解决这个问题?
或者有没有办法使用回收器而不是 gridview 但连续 2 个项目?
您可以将 RecyclerView 与 GridLayoutManager 一起使用 Class
更多关于这里 GridLayoutManager
GridLayoutManager recyclerViewLayoutManager = new GridLayoutManager(context,2);//context is your activity and 2 is number of columns
将您的 GridView 放入 ScrollView 中。
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<GridView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@id/dynamicLayout"
android:numColumns="2"
android:id="@+id/questionChoicesRecycler">
</GridView>
</ScrollView>
我有一个回收视图,这个回收视图的项目是这样的:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/question_bkg"
android:orientation="vertical"
>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/questionTitle"
android:padding="10dp"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:id="@+id/dynamicLayout"
android:layout_below="@id/questionTitle"
android:layout_alignParentLeft="true"></LinearLayout>
<GridView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@id/dynamicLayout"
android:numColumns="2"
android:id="@+id/questionChoicesRecycler"></GridView>
</RelativeLayout>
当我设置 recyclerView.setNestedScrollingEnabled(true);
但我仍然无法在 gridview 中滚动。我怎样才能解决这个问题?
或者有没有办法使用回收器而不是 gridview 但连续 2 个项目?
您可以将 RecyclerView 与 GridLayoutManager 一起使用 Class 更多关于这里 GridLayoutManager
GridLayoutManager recyclerViewLayoutManager = new GridLayoutManager(context,2);//context is your activity and 2 is number of columns
将您的 GridView 放入 ScrollView 中。
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<GridView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@id/dynamicLayout"
android:numColumns="2"
android:id="@+id/questionChoicesRecycler">
</GridView>
</ScrollView>