开发者

Android gallery slideshow animation

I'm developing a gallery app, in this app I'm displaying images in slideshow using gallery. It's working fine, but I want to add some animation. I can apply only one animation with this code but I want to add two animation effects in gallery view. Say in translation effect, right-to-center and center-to-left. Please anyone help me out.

public void slidShow(){

     Runnable runnable = new Runnable() {

        @Override
        public void run() {
            myslideshow();
            handler.postDelayed(this, 3000);                
        }
    };
    new Threa开发者_StackOverflow中文版d(runnable).start();
}

private void myslideshow(){
    PicPosition = gallery.getSelectedItemPosition() +1;             
    if (PicPosition >=  bitmaps.size()){
        PicPosition =  gallery.getSelectedItemPosition(); //stop    
    } 
    else{
        Animation inFromRight = new TranslateAnimation(
                Animation.RELATIVE_TO_PARENT, +1.0f,
                Animation.RELATIVE_TO_PARENT,  0.0f,
                Animation.RELATIVE_TO_PARENT,  0.0f,
                Animation.RELATIVE_TO_PARENT,  0.0f);
        inFromRight.setDuration(500);
        inFromRight.setInterpolator(new AccelerateInterpolator()); 
        gallery.startAnimation(inFromRight);
        gallery.setSelection(PicPosition);  

    }
}


Use Xml based animation Create a Xml file in folder res/anim/animate.xml

put the code

  <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"/>// change this to increase the 
time for image to stay 

</set>

now in your function myslideshow() change

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

Thats all.....

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜