Im trying to write a very basic android app that displays around 5 pictures one after each other on the screen. I want it to display a different picture after about 10 seconds. Can anyone advise me on how I would go around this. Below i have outlined what i would be looking for.
Picture 1
Picture 2
Picture 3
Picture 4
Picture 5
display full screen Picture 1 wait 10 seconds Remove Picture 1 and Display Picture 2 Wait 10 seconds Remove Picture 2 and Display Picture 3 Wait 10 seconds Remove Picture 3 and Display Picture 4 Wait 10 seconds Remove Picture 4 and Display Picture 5 Wait 10 seconds
Start again...thanks
Android image slider slides one entire screen to another screen. Image slider is created by ViewPager which is provided by support library. To implement image slider, you need to inherit ViewPager class which extends PagerAdapter.
Simple Image Slider Java Program using SwingJButton is also known as a push button. The user presses or clicks a JButton to perform an action. Upon clicking the button the required action is performed. The Java ActionListener is notified whenever you click on the button. It is notified against ActionEvent.
You can use viewflipper for this:
view_flipper.xml:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<ViewFlipper
android:id="@+id/viewflipper"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:autoStart="true"
android:flipInterval="2000" >
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/picture1" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/picture2" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/picture3" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/picture4" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/picture5" />
</ViewFlipper>
</RelativeLayout>
Mention this xml file in onCreate of your mainActivity. Like:
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.view_flipper);
}
Thats it. After loading layout it will automatically start animating because we mention autoStart:true in xml.
You can use View flipper to slide your images and to do same automatically at some interval,use TimerTask along with View Flipper.
Inside TimerTask, use Viewflipper.showNext();
Have a look at this post.
Also have a look at startFlipping() and setFlipInterval() methods in ViewFlipper class
http://android-er.blogspot.com/2011/03/auto-flipping-of-viewflipper.html
http://javatechig.com/android/android-viewflipper-example
You can ask if you have any further queries..
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With