Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2014
37
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.64 KB | None | 0 0
  1. <ImageSwitcher
  2. android:id="@+id/imageswitcherID"
  3. <!-- insert another value to the view like layout width and height or margin -->
  4. android:inAnimation="@anim/fade_in"
  5. android:outAnimation="@anim/fade_out"
  6. >
  7.  
  8. <ImageView
  9. android:id="@+id/imageview1"
  10. <!-- another value here -->
  11. android:background="@drawable/your_drawable01"
  12. />
  13.  
  14. <ImageView
  15. android:id="@+id/imageview2"
  16. <!-- another value here -->
  17. android:background="@drawable/your_drawable02"
  18. />
  19.  
  20. </ImageSwitcher>
  21.  
  22. int seconds = 0;
  23. ImageSwitcher imgswitch;
  24. ...
  25. @Override
  26. protected void onCreate(Bundle savedInstanceState){
  27. super.onCreate(savedInstanceState);
  28. setContentView(R.layout.your_layout);
  29.  
  30. imgswitch = (ImageSwitcher)findViewById(R.id.imageswitcherID);
  31.  
  32. SwitchingImages();
  33. }
  34. ...
  35. private void SwitchingImages(){
  36. Thread SwImg = new thread(){
  37. @Override
  38. public void run(){
  39. try{
  40. while(seconds <= 4){
  41. sleep(1000); //sleep for 1 seconds
  42. runOnUiThread(new Runnable(){
  43. @Override
  44. public void run(){
  45. imgswitch.showNext(); //will switch images every 1 seconds
  46. if(seconds >= 4){
  47. return; //stop the thread when 4 seconds elapsed
  48. }
  49. seconds += 1;
  50. }
  51. });
  52. }
  53. }catch(InterruptedException e){
  54. e.printStackTrace();
  55. }
  56. }
  57. };
  58. SwImg.start();
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement