开发者

Android ViewPager with previous and next pages visible?

开发者 https://www.devze.com 2023-04-12 09:39 出处:网络
I am currently building a horizontal gallery of videos. I\'d like to make something like that with only one video centered and part of previous and next videos:

I am currently building a horizontal gallery of videos.

I'd like to make something like that with only one video centered and part of previous and next videos:

Android ViewPager with previous and next pages visible?

I first opted for a Gallery but its limitations made me look for something else. I'd like to show a page indicator and it is quite difficult to implement using a Gallery.

The second option was to go for a ViewPager from Android Compatibility library. I found a way to implement a page indicator over it. But now, how to partly开发者_Go百科 show left and right pages?


I used a negative page margin to partly show the next and the previous pages. The fading edge property can be used to make previous/next page fade:

ViewPager examplePager = (ViewPager) findViewById(R.id.exampleView);
examplePager.setPageMargin(-50);
examplePager.setHorizontalFadingEdgeEnabled(true);
examplePager.setFadingEdgeLength(30);

The lastest support package (revision 4, October 2011) is also required for this to work


Android ViewPager with previous and next pages visible?

Use this code in recyclerview and use snap helper

recyclerView.setAdapter(mAdapter);
LinearLayoutManager layoutManager = new 
LinearLayoutManager(getContext(), LinearLayoutManager.HORIZONTAL, 
false);

recyclerView.setLayoutManager(layoutManager);
    new LinearSnapHelper().attachToRecyclerView(recyclerView);

 recyclerView.setScrollingTouchSlop(  recyclerView.TOUCH_SLOP_PAGING);

more info about snaphelper layout

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号