Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 10th, 2012  |  syntax: None  |  size: 1.83 KB  |  hits: 16  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Android swapping two images with animation
  2. <?xml version="1.0" encoding="utf-8"?>
  3. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  4. android:orientation="vertical"
  5. android:layout_width="fill_parent"
  6. android:layout_height="fill_parent"
  7. >
  8. <Button
  9. android:id="@+id/btn1"
  10. android:text="Button 1"
  11. android:layout_width="fill_parent"
  12. android:layout_height="45dip"
  13. android:layout_marginTop="10dip"
  14. />
  15.  
  16. <Button
  17. android:id="@+id/btn2"
  18. android:text="Button 2"
  19. android:layout_width="fill_parent"
  20. android:layout_height="45dip"
  21. android:layout_marginTop="10dip" />
  22.  
  23. <Button
  24. android:id="@+id/btn3"
  25. android:text="Button 3"
  26. android:layout_width="fill_parent"
  27. android:layout_height="wrap_content"
  28. android:layout_marginTop="10dip"
  29. />
  30.  
  31. <Button
  32. android:id="@+id/btn4"
  33. android:text="Button 4"
  34. android:layout_width="fill_parent"
  35. android:layout_height="wrap_content"
  36. android:layout_marginTop="10dip"
  37. />
  38. </LinearLayout>
  39.        
  40. import android.app.Activity;
  41.   import android.os.Bundle;
  42.   import android.view.animation.Animation;
  43.   import android.view.animation.TranslateAnimation;
  44.   import android.widget.Button;
  45.  
  46.   public class LayoutMargingActivity extends Activity
  47.   {
  48. Button b1, b2, b3, b4;
  49.  
  50. TranslateAnimation left, right;
  51. public void onCreate(Bundle savedInstanceState)
  52. {
  53.     super.onCreate(savedInstanceState);
  54.     setContentView(R.layout.main);
  55.  
  56.     left = new TranslateAnimation(-480, 10, 0, 10);
  57.     right= new TranslateAnimation( 480, 10, 0, 10);
  58.  
  59.     left.setDuration(2000);
  60.     right.setDuration(2000);
  61.  
  62.     left.setRepeatCount( 1 );
  63.     right.setRepeatCount( 1 );
  64.  
  65.     b1 =(Button)findViewById( R.id.btn1);
  66.     b2 =(Button)findViewById( R.id.btn2);
  67.     b3 =(Button)findViewById( R.id.btn3);
  68.     b4 =(Button)findViewById( R.id.btn4);
  69.  
  70.     b1.startAnimation(left);
  71.     b2.startAnimation(right);
  72.     b3.startAnimation(left);
  73.     b4.startAnimation(right);
  74. }