Android 自动推进画廊动画

Android 自动推进画廊动画,android,animation,android-gallery,Android,Animation,Android Gallery,我有一个画廊小部件设置自动前进每10000毫秒。然而,视图之间的转换是即时的,我更希望有一个转换 我的推进方法是这样的: private void tickerAdvance() { int selectedItemPosition = mTickerGallery.getSelectedItemPosition(); if (selectedItemPosition + 1 == mTickerGallery.getCount()) { mTickerGalle

我有一个画廊小部件设置自动前进每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”,但是状态之间的转换仍然会立即弹出。

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

这是你怎么做的

假设您已经完成了周期性自动推进的必要步骤,现在执行以下代码

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

我的答案是Gallery API非常不可扩展。有多个包private或private方法可以在没有混乱的情况下解锁此功能,包括moveNext、FlingRunTable.startwithdistance和scrollToChild。唉,它们都不可用


相反,我能想到的最好的答案是放弃选择,以获得我所需要的所有行为。在SETSELECT方法中,我反转减速算法以计算计算距离的速度,然后调用onFling。这是一个令人讨厌的难题,通过保护或公开上述任何一种方法都可以让它变得更好(我不明白为什么至少moveNext和scrollToChild不应该被保护)。

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

布尔avoidSound=false

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(),它就会生成一个动画

我不知道你是怎么做的,但我有一个用horizontalscrollview制作的动画,它通过在scrollview上设置动画来生成过渡动画。除非我误用了一些东西,否则onScoll似乎没有更好的行为。虽然这使我考虑使用OnfLink,这将有适当的行为。不过,这两种方法都让我感到困扰,因为我不喜欢这样使用手势事件处理程序……但这可能是唯一合理的方法。