中心项目更大的Android ViewPager

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

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

How to target newer versions in .gitlab-ci.yml using auto devops (java 11 instead of 8 and Android 31 instead of 29)(如何在.gitlab-ci.yml中使用自动开发工具(Java 11而不是8,Android 31而不是29)瞄准较新的版本)
Android + coreLibraryDesugaring: which Java 11 APIs can I expect to work?(Android+core LibraryDesugering:我可以期待哪些Java 11API能够工作?)
How to render something in an if statement React Native(如何在If语句中呈现某些内容Reaction Native)
How can I sync two flatList scroll position in react native(如何在本机Reaction中同步两个平面列表滚动位置)
Using Firebase Firestore in offline only mode(在仅脱机模式下使用Firebase FiRestore)
Crash on Google Play Pre-Launch Report: java.lang.NoSuchMethodError(Google Play发布前崩溃报告:java.lang.NoSuchMethodError)