简体   繁体   中英

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.

Thanks.

在此处输入图片说明

Group set of 10 items into single recycler item view and repeat that item using Horizontal RecyclerView as in

在此处输入图片说明

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.

```

@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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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