Android gallery slideshow

I am developing a gallery application, in this application I display images in a slide show using a gallery. It works fine, but I want to add animation. I can only apply one animation with this code, but I want to add two animation effects to the gallery. Say the translation effect, on the right to the center and the center on the left. Please help me.

public void slidShow(){ Runnable runnable = new Runnable() { @Override public void run() { myslideshow(); handler.postDelayed(this, 3000); } }; new Thread(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); } } 
+4
source share
1 answer

Use Xml-based animation Create an Xml file in the res / anim / animate.xml folder

Enter a 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 myslideshow () function change

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

That's all.....

+2
source

All Articles