I want to create a ViewPager with
- The selected center item being bigger than others
- Portion of Previous & Next items being always visible.
I am using viewPager.setPageMargin(-20);
to make portion of Previous & Next items visible. But, how to make selected center item little bit bigger than other items.
Asked
Active
Viewed 3,088 times
3

Manjunath
- 2,063
- 2
- 29
- 60
1 Answers
-1
you can set the Layout parameters to be x% bigger in the onPageSelected() method.
ViewPager pager ;
int prevIndex = 0;
int oldWidth, oldHeight,
//initialize these to be bigger than the old ones
newWidth, newHeight;
pager.setOnPageChangeListener(new OnPageChangeListener() {
public void onPageSelected(int index) {
// Set the layout params of the newly selected page to be the large width and height
View v = pager.getChildAt(index);
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(
newWidth, newHeight);
v.setLayoutParams(params);
// Don't forget to set the past view to the old layout params.
View oldV = pager.getChildAt(prevIndex);
RelativeLayout.LayoutParams oldParams = new RelativeLayout.LayoutParams(
oldWidth, oldHeight);
oldV.setLayoutParams(oldParams);
prevIndex = index;
}
public void onPageScrolled(int arg0, float arg1, int arg2) {
// TODO Auto-generated method stub
}
public void onPageScrollStateChanged(int arg0) {
// TODO Auto-generated method stub
}
});

Eddy K
- 874
- 6
- 12
-
You're very welcome :) I hope that helps! let me know if it doesn't, maybe there's another way around it. – Eddy K Jul 03 '13 at 00:57
-
Hey all, I'm trying to something similar. My Viepager items are fragments containing an imageview. I can't seem to grab the items view to change the layout size. – daesu Sep 09 '13 at 11:06