Android Studio 中的可重新排列的卡片视图和 Activity 中的多个卡片视图

Rearrangeable cardviews in Androidstudio and more than one Cardview in an Activity

1)如何在 Androidstudio 中制作一个可以重新排列 5-6 个卡片视图的 Activity,就像在 Windows 10 开始菜单中一样?

Example Activity (Windows 10) with views you can rearrange

2)如何制作一个Activity多于一个的Cardview(就像上图(windows 10 Startingmenu))?

任何提示将不胜感激,谢谢。

是的,你可以做到。你需要将 RecyclerView 与 GridLayoutManager 一起使用 最后你为你的 List

设置跨度大小

第一组指定您在网格中需要的列数,在您的情况下是 2

     gridLayoutManager = new GridLayoutManager(getActivity(), 2);

然后检查视图的位置并相应地设置跨度大小

gridLayoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {
        @Override
        public int getSpanSize(int position) {

            //depanding upon the type of data  set the span-size if it is header take the whole space in the row
            //also check the orientation and set the span-size
            if (mAdapter.getItemViewType(position) == Adapter.ITEM_VIEW_TYPE_HEADER) {
                    return 2;
                }
            }
            // if the type is item type keep the span-size as normal which is one
            if (mAdapter.getItemViewType(position) == Adapter.ITEM_VIEW_TYPE_ITEM) {
                return 1;
            }
            return -1;
        }
    });