【问题标题】:Autoadvancing gallery animation自动前进画廊动画
【发布时间】:2011-11-27 10:58:53
【问题描述】:

我有一个画廊小部件设置为每 10000 毫秒自动前进一次。然而,视图之间的转换是即时的,我更愿意进行转​​换。

我的推进方法是这样的:

private void tickerAdvance() {
    int selectedItemPosition = mTickerGallery.getSelectedItemPosition();
    if (selectedItemPosition + 1 == mTickerGallery.getCount()) {
        mTickerGallery.setSelection(0, true);
    } else {
        mTickerGallery.setSelection(selectedItemPosition + 1, true);
    }
}

我的印象是,将动画设置为 true 会导致它在状态之间进行动画处理。在我的 XML 中,我还添加了 animationDuration="500",但是转换仍然会立即在状态之间弹出。

【问题讨论】:

  • 我不知道你是怎么做的,但我有一个使用horizo​​ntalscrollview制作的,只需在scrollview上设置动画即可制作过渡动画。

标签: android animation android-gallery


【解决方案1】:

问题是因为您使用了 setSelection() 显然不会给您滚动画廊的感觉。因此,您必须覆盖画廊的 onScroll() 而不是使用 setSelection()

这是你的做法。

假设您已完成定期自动推进的必要步骤,现在执行此代码。

MotionEvent e1, e2;
gallery.onScroll(e1, e2, scroll_limit   , 0);    //scroll limit is your integer variable for scroll limit.

【讨论】:

  • 除非我误用了某些东西,否则 onScoll 似乎没有更好的行为。尽管这使我考虑使用具有适当行为的 onFling 。这两种方法都困扰着我,因为我不喜欢这样使用手势事件处理程序的想法……但这可能是唯一合理的方法。
【解决方案2】:

我想出的答案是 Gallery API 非常不可扩展。有多种包私有或私有方法可以解锁此功能而无需任何麻烦,包括 moveNext、FlingRunnable.startwithdistance 和 scrollToChild。唉,它们都不可用。

相反,我能想出的最佳答案是重写 setSelection 以获得我需要的所有行为。在 setSelection 方法中,我反转减速算法以计算计算距离的速度,然后调用 onFling。通过将上述任何方法设置为受保护或公开(我无法理解为什么至少 moveNext 和 scrollToChild 不应该是),这是一个令人讨厌的组合。

【讨论】:

    【解决方案3】:

    我有一个类似的任务来制作项目到项目的动画,我决定选择画廊,所以我尝试了很多东西,但最好的方法是子类化画廊并添加这个:

    布尔避免声音=假;

    public void showNext() {
        avoidSound = true;
        this.onKeyDown(KeyEvent.KEYCODE_DPAD_RIGHT, null);
    }
    
    
    public void playSoundEffect(int soundConstant) {
        if (avoidSound) {
            avoidSound = false;
        } else {
            super.playSoundEffect(soundConstant);
        }
    }
    

    只需调用 showNext(),它就会做一个动画

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-04-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多