我想创建一个带有
的ViewPager
- 所选中心项目比其他项目大
- 前一部分和一部分下一个项目始终可见。
我正在使用viewPager.setPageMargin(-20);
制作Previous&的一部分下一项可见。但是,如何使选定的中心项目比其他项目略大。
答案 0 :(得分:-1)
您可以在onPageSelected()方法中将Layout参数设置为x%。
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
}
});