Android ViewPager with center item bigger(中心项目更大的Android ViewPager)
问题描述
我想用
创建一个 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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:中心项目更大的Android ViewPager


基础教程推荐
- Kivy Buildozer 无法构建 apk,命令失败:./distribute.sh -m “kivy"d 2022-01-01
- 在 gmail 中为 ios 应用程序检索朋友的朋友 2022-01-01
- 当从同一个组件调用时,两个 IBAction 触发的顺序是什么? 2022-01-01
- 如何让对象对 Cocos2D 中的触摸做出反应? 2022-01-01
- 如何在没有IB的情况下将2个按钮添加到右侧的UINavigationbar? 2022-01-01
- android 应用程序已发布,但在 google play 中找不到 2022-01-01
- UIWebView 委托方法 shouldStartLoadWithRequest:在 WKWebView 中等效? 2022-01-01
- 如何在 iPhone 上显示来自 API 的 HTML 文本? 2022-01-01
- Android:对话框关闭而不调用关闭 2022-01-01
- 如何在 UIImageView 中异步加载图像? 2022-01-01