Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <ImageSwitcher
- android:id="@+id/imageswitcherID"
- <!-- insert another value to the view like layout width and height or margin -->
- android:inAnimation="@anim/fade_in"
- android:outAnimation="@anim/fade_out"
- >
- <ImageView
- android:id="@+id/imageview1"
- <!-- another value here -->
- android:background="@drawable/your_drawable01"
- />
- <ImageView
- android:id="@+id/imageview2"
- <!-- another value here -->
- android:background="@drawable/your_drawable02"
- />
- </ImageSwitcher>
- int seconds = 0;
- ImageSwitcher imgswitch;
- ...
- @Override
- protected void onCreate(Bundle savedInstanceState){
- super.onCreate(savedInstanceState);
- setContentView(R.layout.your_layout);
- imgswitch = (ImageSwitcher)findViewById(R.id.imageswitcherID);
- SwitchingImages();
- }
- ...
- private void SwitchingImages(){
- Thread SwImg = new thread(){
- @Override
- public void run(){
- try{
- while(seconds <= 4){
- sleep(1000); //sleep for 1 seconds
- runOnUiThread(new Runnable(){
- @Override
- public void run(){
- imgswitch.showNext(); //will switch images every 1 seconds
- if(seconds >= 4){
- return; //stop the thread when 4 seconds elapsed
- }
- seconds += 1;
- }
- });
- }
- }catch(InterruptedException e){
- e.printStackTrace();
- }
- }
- };
- SwImg.start();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement