Android的ViewPager手动调用PageTransformer transformPage [英] Android ViewPager manually call PageTransformer transformPage

查看:782
本文介绍了Android的ViewPager手动调用PageTransformer transformPage的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个ViewPager与PageTransformer实现,做一些时髦的东西到ViewPager的下一个页面。我的实现看起来是这样的:

I have a ViewPager with the PageTransformer implementation that does some funky stuff to the next page of the ViewPager. My implementation looks like this:

class ZoomOutPageTransformer implements ViewPager.PageTransformer {
private static final float MIN_SCALE = 0.85f;
private static final float MIN_ALPHA = 0.5f;

@Override
public void transformPage(View view, float position) {
    int pageWidth = view.getWidth();

    if (position < -1) { // [-Infinity,-1)
        // This page is way off-screen to the left.
        view.setAlpha(0);

    } else if (position <= 0) { // [-1,0]
        // Use the default slide transition when moving to the left page


    } else if (position < 1) { // (0,1]
      do some funky stuff to the page currently being scrolled into the main view on scrolling left


    } else if (position==1) {
       do some funky stuff to the next page
    }

    else { // (1,+Infinity]
        // This page is way off-screen to the right.
        view.setAlpha(1);
    }
}

}

的问题是,这些变换动画一旦该寻呼机被装载是可用的,但它们不提供给我viewpager的第一片段。即一片段被加载在第一时间,在 transformPage 方法不被调用。有没有办法手动调用 transformPage 的方法?即当我在 onCreateView 设置我的ViewPager?还是别的地方?

The problem is that these transform animations are available as soon as the pager is loaded, but they're not available to the first fragment of my viewpager. I.e. the first time a fragment is loaded, the transformPage method is not being called. Is there a way to call the transformPage method manually? I.e. when I'm setting up my ViewPager inside onCreateView? Or somewhere else?

推荐答案

根据开发者的网站,

谷歌开发者

每当可见/附页滚动一个PageTransformer被调用。这提供了一个机会,利用动画属性自定义转换应用到网页浏览应用
所以,你不会看到任何过渡动画,当寻呼机被加载首次。

A PageTransformer is invoked whenever a visible/attached page is scrolled. This offers an opportunity for the application to apply a custom transformation to the page views using animation properties So, you wouldn't see any transition animation when the pager is loaded for the first time.

这是一个你一直在使用一个不错的黑客,但我不知道你是否已经尝试过,但在加载时,第一次可以动画viewpager作为一个整体本身。

That's a good hack that you have been using, but I don't know if you had tried it already but can you animate the viewpager as a whole itself when it loads for the first time.

这篇关于Android的ViewPager手动调用PageTransformer transformPage的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆