简体   繁体   English

如何在Android上先显示Horizo​​ntal RecyclerView的前10个项目,然后滑动以显示另外10个项目?

[英]How to show Horizontal RecyclerView first 10 items and then swipe to show another 10 items in android?

I have a Vertical recyclerView with Horizontal recyclerView.Currently i am showing 10 elements in each section (Horizontal recyclerView).. If more than 10 elements i have to first 10 elements then i have to swipe show another 10 elements. 我有一个卧式recyclerView和卧式recyclerView。当前,我在每个部分中显示了10个元素(卧式recyclerView)。如果我必须在前10个元素中包含10个以上的元素,则必须滑动显示另外10个元素。

Thanks. 谢谢。

在此处输入图片说明

Group set of 10 items into single recycler item view and repeat that item using Horizontal RecyclerView as in 将一组10个项目分组到单个recycler项目视图中,然后使用Horizo​​ntal RecyclerView重复该item ,如下所示

在此处输入图片说明

You want to show just 10 items at first and swipe to show more items, The better way is to let your recyclerview's width adaptives 10 items total width, so you can custom a LayoutManager for your horizontal recyclerview, and implement it's onMeasure method to set the width of the recyclerview. 您只想只显示10个项目,然后滑动以显示更多项目,更好的方法是让recyclerview的宽度自适应总宽度为10个项目,因此您可以为水平recyclerview自定义LayoutManager,并实现onMeasure方法来设置recyclerview的宽度。

``` ```

@Override
public void onMeasure(RecyclerView.Recycler recycler, RecyclerView.State state, int widthSpec,int heightSpec) {
    View view = recycler.getViewForPosition(0);
    measureChild(view, widthSpec, heightSpec);
    //int recyclerViewW = ...;
    //int recyclerViewH = ...;
    //setMeasuredDimension(recyclerViewW, recyclerViewH);
}

``` ```

By the way, if the items you want to show is not fixed in size, this way is not eligible. 顺便说一句,如果您要显示的项目的大小不是固定的,则不符合此条件。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM