繁体   English   中英

如何设置动画到画廊的特定位置

[英]How to animate to a specific position of a gallery

我想移动到带有动画的画廊中的特定位置。 例如,我在图库中有100个元素,实际位置是0。我想缓慢移动(动画)到位置99。

我尝试了以下命令,这似乎很有希望。 但它不设置动画:-(

gallery.setSelection(int position, boolean animate)

有什么提示吗?

也许您必须使用这样的东西:创建animate.xml文件

<set xmlns:android="http://schemas.android.com/apk/res/android"     android:shareInterpolator="true">
<translate 
    android:fromXDelta="0%p" android:toXDelta="50%p" // change this to decide the range
    android:duration="500" android:startOffset="0"/>
<translate 
    android:fromXDelta="0%p" android:toXDelta="100%p" 
    android:duration="500" android:startOffset="500"/>

并在您的代码中使用以下代码:

Animation inFromRight =  AnimationUtils.loadAnimation(this, R.anim.animate);
gallery.startAnimation(inFromRight);
gallery.setSelection(PicPosition);  

这个想法来自这个链接:

Android图库幻灯片动画

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM