android imageSwitcher Example Oreo Source Code

Android imageSwitcher example source code support Oreo

ImageSwitcher android useful instead of image slider. A great alternative of image slider change image each time when button is clicked. Visit official link to know and better information about ImageSwitcher. Get complete video tutorial of android ImageSwitcher used to change image on Button click with next Previous feature.

package Write your package name here;
import android.app.ActionBar;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.Button;
import android.widget.ImageSwitcher;
import android.widget.ImageView;
import android.widget.ViewSwitcher;

public class AndroidImageSwitcherExample extends AppCompatActivity {

    ImageSwitcher switchImage;
    Button nextImageButton;

    int storeImages[] = {R.drawable.image1, R.drawable.image2, R.drawable.Attraction3, 
R.drawable.NextGenEarn4, R.drawable.BungBangs5};

    int switchingImage = storeImages.length;
    int counter = -1;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        switchImage = (ImageSwitcher) findViewById(R.id.imageSwitcher);
        nextImageButton = (Button) findViewById(R.id.nextImage);

        switchImage.setFactory(new ViewSwitcher.ViewFactory() {

            public View makeView() {
                // TODO Auto-generated method stub
                
                ImageView imageViewSwitch = new ImageView(getApplicationContext());
                imageViewSwitch.setScaleType(ImageView.ScaleType.FIT_CENTER);
                imageViewSwitch.setLayoutParams(new ImageSwitcher.LayoutParams(ActionBar.LayoutParams.MATCH_PARENT, ActionBar.LayoutParams.MATCH_PARENT));
                imageViewSwitch.setImageResource(R.drawable.image1);
                return imageViewSwitch;
            }
        });

        //Android default animation. No additional animation file require.
        Animation animationOut = AnimationUtils.loadAnimation(this, android.R.anim.slide_out_right);
        Animation animationIn = AnimationUtils.loadAnimation(this, android.R.anim.slide_in_left);

        switchImage.setOutAnimation(animationOut);
        switchImage.setInAnimation(animationIn);
    }

    public void nextImageButton(View view) {
        counter++;
        if (counter == switchingImage)
            counter = 0;
        switchImage.setImageResource(storeImages[counter]);
    }
}


<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#ff9da4"
    >

    <ImageSwitcher
        android:id="@+id/imageSwitcher"
        android:layout_width="match_parent"
        android:layout_height="210dp"
        android:background="#aaf1ff"
        android:layout_marginTop="162dp"
        android:layout_alignParentTop="true"
        android:layout_alignParentStart="true" />

    <Button
        android:id="@+id/nextImage"
        android:layout_width="300dp"
        android:layout_height="wrap_content"
        android:onClick="nextImageButton"
        android:text="Next Image"
        android:textSize="30sp"
        android:textStyle="bold"
        android:textColor="#00bfbf"
        android:background="#c676b5f9"
        android:layout_marginTop="44dp"
        android:layout_below="@+id/imageSwitcher"
        android:layout_centerHorizontal="true" />

    <TextView
        android:id="@+id/android_image_switcher_tutorial"
        android:layout_width="match_parent"
        android:layout_height="30dp"
        android:textSize="30sp"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:textStyle="bold"
        android:autoLink="web"
        android:gravity="bottom|center"
        android:text="NextGenEarn.com"
        android:layout_alignParentBottom="true"
        android:layout_alignParentStart="true" />

    <TextView
        android:id="@+id/textView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textColor="#329df5"
        android:textStyle="bold"
        android:textSize="45sp"
        android:text="- IMAGE SWITCHER SLIDE IMAGE -"
        android:layout_alignParentTop="true"
        android:layout_alignParentStart="true" />

</RelativeLayout>

Android get latest most featured source code example with video support all newer OS version in ATTRACTION ANDROID.

Add a Comment

Your email address will not be published. Required fields are marked *