3

我想创建一个 ViewPager
- 选定的中心项目比其他项目大
- 上一个和下一个项目的部分始终可见。

viewPager.setPageMargin(-20);用来使上一个和下一个项目的一部分可见。但是,如何使选定的中心项目比其他项目大一点。

4

1 回答 1

-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

        }
    });
于 2013-07-03T00:44:38.470 回答