简体   繁体   English

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

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

I would like move to a specific position in a gallery with animation. 我想移动到带有动画的画廊中的特定位置。 For example, I have 100 elements in a gallery and the actual position is 0. I would like to move slowly (animated) to position 99. 例如,我在图库中有100个元素,实际位置是0。我想缓慢移动(动画)到位置99。

I tried the following command, which seemed promising. 我尝试了以下命令,这似乎很有希望。 But it does not animate :-( 但它不设置动画:-(

gallery.setSelection(int position, boolean animate)

Any hints? 有什么提示吗?

Maybe you have to use something like this: create animate.xml file 也许您必须使用这样的东西:创建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"/>

and in your code use this: 并在您的代码中使用以下代码:

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

The idea is from this link: 这个想法来自这个链接:

Android gallery slideshow animation Android图库幻灯片动画

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

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