Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set padding between ViewPager pages while keeping the page full-width [duplicate]

I'm using the new ViewPager-view from the Android compatibility library, and I can't figure out how to get padding between the pages so that when you're swiping between them, there's a visible border.

My ViewPager width is set to fill_parent so it takes up the entire width of the display. I can get this border between the pages by setting android:padding on the ViewPager, but that has the added (unwanted) effect of reducing the visible size of the page when it is fully displayed.

I guess what I need is to introduce a border outside the width of the view somehow, if that even makes sense...

The new Android Market does this the way I'd like, but I just can't figure out how it's accomplished.

like image 849
chuz Avatar asked Aug 16 '11 02:08

chuz


1 Answers

There's currently no way to do that in the XML layout, but you can use the following functions in java:

setPageMargin(int marginPixels)
setPageMarginDrawable(drawable d)
setPageMarginDrawable(int resId)

You'll need to grab the pager from your XML layout first:

ViewPager pager = (ViewPager) findViewById(R.id.pager);
like image 147
Quint Stoffers Avatar answered Oct 07 '22 00:10

Quint Stoffers