How could i insert some padding between the pages inside view-pager like in the market app - the black line
Asked
Active
Viewed 1.1k times
7

Tomer Mor
- 7,998
- 5
- 29
- 43
-
add view with black color. height as match and width as 3dp. – Padma Kumar Aug 13 '12 at 13:25
3 Answers
34
This worked for me. I just set the margin and filled it with a color.
viewPager.setPageMargin(20); // TODO Convert 'px' to 'dp'
viewPager.setPageMarginDrawable(R.color.black);
EDIT: To convert dp to pixel conversion I used:
int px = Math.round(TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 20, getResources().getDisplayMetrics()));
mViewPager.setPageMargin(px);
mViewPager.setPageMarginDrawable(R.color.black);

SammyT
- 759
- 1
- 9
- 19
-
6Note that `setPageMargin(int)` takes a pixel value. Instead of providing a number, you might want to do dp conversions. – nhaarman Jan 07 '14 at 13:25
16
That is a new api for the ViewPager
called the margin, a link to it can be found setPageMargin()
. Make sure you are using the latest support library.

AskNilesh
- 67,701
- 16
- 123
- 163

HandlerExploit
- 8,131
- 4
- 31
- 50
2
Use This method:
public void setPageMarginDrawable (int resId)
You will be able to set a drawable that will be used to fill the margin between pages.

K_Anas
- 31,226
- 9
- 68
- 81