Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Auto Slide image in Android [closed]

Tags:

android

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

like image 449
user3226468 Avatar asked Jan 23 '14 09:01

user3226468


People also ask

What is image slider Android?

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.

What is image slider in java?

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.


2 Answers

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.

like image 113
user543 Avatar answered Oct 18 '22 21:10

user543


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..

like image 44
Jigar Pandya Avatar answered Oct 18 '22 21:10

Jigar Pandya