【发布时间】:2020-10-16 15:02:26
【问题描述】:
我有一个使用 recyclerView 和 LinearLayoutManager 的 Android 应用程序。我的印象是,将 LinearLayoutManager 更改为 GridLayoutManager(参见下面的注释行和下一行)只会给我一个网格。但是没有任何变化,我仍然看到线性列表,每行一项,一列。
recyclerView = view.findViewById(R.id.item_setup_recycler_view);
recyclerView.setHasFixedSize(true);
//recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
recyclerView.setLayoutManager(new GridLayoutManager(getActivity(), 2));
adapter = new ItemSetupRecyclerViewAdapter(getActivity(), kids);
recyclerView.setAdapter(adapter);
在我看到网格之前,如果还有其他需要更改的地方,有人可以告诉我吗?
这是recyclerView的xml:
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/feed_recycle_view"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginBottom="8dp"
android:clipToPadding="false"
android:paddingBottom="74dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView8"
app:layout_constraintVertical_bias="0.0">
</androidx.recyclerview.widget.RecyclerView>
提前致谢
【问题讨论】:
-
看看这个,可能你少了一步:stackoverflow.com/questions/40587168/…
-
你能分享你的xml吗?
-
@ChintanSoni 我刚刚做了。谢谢
-
看来你是为 item_setup_recycler_view 设置的,而不是你发布 feed_recycle_view 的 XML
标签: android android-recyclerview gridlayoutmanager