我想用
创建一个 ViewPager- 选定的中心项目比其他项目大
- 以前的部分 &下一项始终可见.
我正在使用 viewPager.setPageMargin(-20);
来制作 Previous &下一个项目可见.但是,如何使选中的中心项比其他项大一点.
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.
可以在 onPageSelected() 方法中将 Layout 参数设置为大 x%.
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
}
});
这篇关于中心项目更大的Android ViewPager的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!