简体   繁体   English

如何在Android中每四个项目之后显示带有水平视图的Recyclerview cardview,例如添加

[英]How can I show Recyclerview cardview with horizontal views like adds after every four items in android

I am developing E Commerce app. 我正在开发电子商务应用程序。 In my app I needs to show items in grid view manner. 在我的应用中,我需要以网格视图的方式显示项目。 But i needs to show one horizontal item (like add)after every four items in grid view manner using recyclerview card view. 但是我需要使用recyclerview卡视图以网格视图的方式在每四个项目之后显示一个水平项目(如添加)。 adds means I am not using google add mob. 添加意味着我不使用google add mob。 I am just show an item like a add in horizontal manner. 我只是以水平方式显示类似添加项的项目。 I am confused. 我很困惑。 any one can help me. 任何人都可以帮助我。

屏幕截图在这里

Try like this. 尝试这样。

    RecyclerView mRecyclerView = (RecyclerView) rootView.findViewById(R.id.card_recycler_view);
    GridLayoutManager glm = new GridLayoutManager(getActivity(), 4);
            glm.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {
                @Override
                public int getSpanSize(int position) {
                    if (position % 5 == 4) {
                        return 4;
                    } else {
                        return 2;
                    }
        }
    });
    mRecyclerView.setLayoutManager(glm);

You can use Recyclerview or Gridview with sticky headers 您可以将Recyclerview或Gridview与粘性标头一起使用

<dependency>
  <groupId>com.tonicartos</groupId>
  <artifactId>stickygridheaders</artifactId>
  <version>1.0.1</version>
</dependency>

https://github.com/DWorkS/AStickyHeader https://github.com/DWorkS/AStickyHeader

http://tonicartos.github.io/StickyGridHeaders/ http://tonicartos.github.io/StickyGridHeaders/

https://github.com/ShamylZakariya/StickyHeaders https://github.com/ShamylZakariya/StickyHeaders

https://github.com/timehop/sticky-headers-recyclerview https://github.com/timehop​​/sticky-headers-recyclerview

you can use StaggeredGridLayoutManager 您可以使用StaggeredGridLayoutManager

private StaggeredGridLayoutManager gaggeredGridLayoutManager;
gaggeredGridLayoutManager = new StaggeredGridLayoutManager(2, 1);
recyclerView.setLayoutManager(gaggeredGridLayoutManager);

for more information follow this link StaggeredGridLayoutManager 有关更多信息,请单击此链接StaggeredGridLayoutManager

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在带有片段的活动中显示RecyclerView和CardView布局? - How can I show RecyclerView and CardView layouts in an activity with a fragment? android-RecyclerView项目:如何在每一行中保存视图的属性? - android - RecyclerView items: how to save properties of Views in every row? Android:如何在CardView中插入RecyclerView? - Android: how can I insert a RecyclerView inside CardView? 带有CardView的Android RecyclerView - 以堆栈形式显示卡片(不是列表) - Android RecyclerView with CardView - show cards in a stack-like (not a list) 如何在recyclerview中显示项目数? - How I can show the number of items in recyclerview? 如何在Android上先显示Horizo​​ntal RecyclerView的前10个项目,然后滑动以显示另外10个项目? - How to show Horizontal RecyclerView first 10 items and then swipe to show another 10 items in android? 如何在水平 RecyclerView 中正确居中第一个和最后一个项目 - How can I properly center the first and last items in a horizontal RecyclerView 如何将 CardView 对齐到水平居中? - How can I align the CardView to center horizontal? 如何在 cardview 中为 recyclerview 对齐 textview - How can I align the textview in cardview for recyclerview 如何将 RecyclerView 和 CardView 实现到片段中? - How can I implement a RecyclerView and a CardView into a fragment?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM