Monday, July 22, 2013

Animate An Image In Android

In android we can animate an ImageView with different multiple ways.  One of the way is to use ImageSwitcher for animation between Images.
You can learn  Animating Image Using ImageSwitcher.

 ImageSwitcher is helpful when we have multiple images and we need to switch between Images, but if we have to rotate an Image, we have to use  RotateAnimation class.

Steps:
  1. Create the RotateAnimation object
  2. Set the Animation Properties.
  3. Start The Animation.

ImageView Animation Example

In this post I have an Image of Ball and rotating it through Top Left corner.

layout.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical" >

        <TextView
            android:layout_marginTop="80dp"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:textStyle="bold"
            android:gravity="center"
            android:textColor="#000099"
            android:textSize="30dp"
            android:text="ImageView Animation Demo" />

        <ImageView
            android:layout_gravity="center_horizontal"
            android:layout_marginTop="120dp"
            android:id="@+id/imageView1"
            android:layout_width="200dp"
            android:layout_height="200dp"
            android:src="@drawable/ball" />
   
</LinearLayout>


MainActivity .java

public class MainActivity extends Activity
{

    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
       
        ImageView image=(ImageView)findViewById(R.id.imageView1);
       
        // Step1 : create the  RotateAnimation object

        RotateAnimation anim = new RotateAnimation(0f, 350f, 15f, 15f);
        // Step 2:  Set the Animation properties
        anim.setInterpolator(new LinearInterpolator());
        anim.setRepeatCount(Animation.INFINITE);
        anim.setDuration(700);

        // Step 3: Start animating the image
         image.startAnimation(anim);

        // Later. if you want to  stop the animation
        // image.setAnimation(null);
    }
}


5 comments:

  1. Hi,
    Thanks for sharing the information with us it was very informative. https://hangup.in

    ReplyDelete
  2. Hello! Our company provides many machine learning experts specializing in data annotation. Our assistants have deep knowledge of annotation techniques and are able to create high quality training datasets. With the experience of our experts, you can count on accurate annotations that greatly contribute to the success of your machine learning models. >> ideas here

    ReplyDelete
  3. Data annotation stands out as a pivotal element within the realm of AI, offering a compelling chance to elevate the efficiency and overall effectiveness of artificial intelligence systems and other software applications. However, the process of sourcing skilled annotation specialists poses its challenges, necessitating the aid of a dedicated online service that expertly curates top-notch data annotation professionals suited to your project's specific needs, special info here.

    ReplyDelete
  4. Whether you work alone or in a large team, this website can help you write better code more quickly. Due to its powerful debugging tools, integrated testing framework, and user-friendly interface, it might expedite your development process and result in high-quality apps in less time. So see this site here for more helpful information!

    ReplyDelete
  5. Outsourcing image annotation tasks allows businesses to focus on their core competencies and strategic initiatives, leaving the data labeling process to experts in the field. Hiring and managing in-house annotators can involve administrative overhead. Remote annotators typically work as contractors or through data labeling companies, reducing administrative burdens for the hiring organization. Reputable remote annotators follow stringent data security and privacy protocols to safeguard sensitive information. This ensures that confidential data remains protected during the annotation process. For more info visit this link.

    ReplyDelete