Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to create cycle Image animation function in android

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 947
    Comment on it

    In the below example I have created cycle animation function. Here I have added Button and ImageView in actvity_main.xml layout then I have created new directory (anim). In anim directory I have created cycle.xml layout and In MainActivity I have used AnimationUtils.loadAnimation function and setOnClickListener method. You can see below program it will clearly describe you to cycle Image animation in android.

    Step(1)activity_main.xml-

    1. <?xml version="1.0" encoding="utf-8"?>
    2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    3. android:layout_width="fill_parent"
    4. android:layout_height="fill_parent"
    5. android:orientation="vertical" >
    6.  
    7.  
    8. <LinearLayout
    9. android:layout_width="fill_parent"
    10. android:layout_height="fill_parent"
    11. android:orientation="horizontal">
    12. <LinearLayout
    13. android:layout_width="wrap_content"
    14. android:layout_height="fill_parent"
    15. android:orientation="vertical"
    16. android:gravity="bottom"
    17. android:layout_margin="30dp">
    18. <ImageView
    19. android:layout_width="wrap_content"
    20. android:layout_height="wrap_content"
    21. android:src="@drawable/one"
    22. android:id="@+id/image"
    23. android:textColor="@color/colorAccent"
    24. android:textStyle="italic"
    25. android:textSize="25dp"/>
    26. </LinearLayout>
    27. <LinearLayout
    28. android:layout_width="fill_parent"
    29. android:layout_height="fill_parent"
    30. android:orientation="vertical">
    31. <Button
    32. android:id="@+id/cycle"
    33. android:layout_marginTop="40dp"
    34. android:layout_width="200dp"
    35. android:layout_height="wrap_content"
    36. android:background="@color/colorAccent"
    37. android:text="Click me"/>
    38. </LinearLayout>
    39. </LinearLayout>
    40. </LinearLayout>
    41.  

    Step(2)-MainActivity-

    1. public class MainActivity extends AppCompatActivity {
    2.  
    3. @Override
    4. protected void onCreate(Bundle savedInstanceState) {
    5. super.onCreate(savedInstanceState);
    6. setContentView(R.layout.activity_main);
    7.  
    8. final Animation animCycle = AnimationUtils.loadAnimation(this, R.anim.cycle);
    9. final ImageView text = (ImageView) findViewById(R.id.image);
    10. Button btnCycle = (Button) findViewById(R.id.cycle);
    11. btnCycle.setOnClickListener(new Button.OnClickListener() {
    12.  
    13. @Override
    14. public void onClick(View arg0) {
    15. text.startAnimation(animCycle);
    16.  
    17. }
    18. });
    19. }
    20.  
    21. }

    Step(3)-In anim directory I have created cycle.xml layout-

    1. <?xml version="1.0" encoding="utf-8"?>
    2. <set xmlns:android="http://schemas.android.com/apk/res/android"
    3. android:interpolator="@android:anim/cycle_interpolator">
    4. <translate
    5. android:fromYDelta="-50%p"
    6. android:toYDelta="0"
    7. android:duration="1800"/>
    8. </set>

     

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Reset Password
Fill out the form below and reset your password: