Create view rotation animation using objectanimator in android programmatically

How to make whole view with rotate animation in android using programming coding.

In this tutorial we are creating view rotation animation with the use of ObjectAnimator class. With this particular class we can rotate any type of view widget. So here is the complete step by step tutorial for Create view rotation animation using objectanimator in android programmatically.

android-project-download-code-button

How to Create view rotation animation using objectanimator in android programmatically.

Code for MainActivity.java file.

 package com.viewrotationanimation_android_examples.com;

import android.animation.ObjectAnimator;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

public class MainActivity extends Activity {

 TextView text;
 Button button;
 ObjectAnimator objectanimator;
 @Override
 protected void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);
 setContentView(R.layout.activity_main);
 
 text = (TextView)findViewById(R.id.textView1);
 button = (Button)findViewById(R.id.button1);
 
 objectanimator = ObjectAnimator.ofFloat(text,"rotation",360);
 
 button.setOnClickListener(new View.OnClickListener() {
 
 @Override
 public void onClick(View v) {
 // TODO Auto-generated method stub
 
 objectanimator.setDuration(3000);
 objectanimator.start();
 
 }
 });
 
 }
}

Code for activity_main.xml layout file.

 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
 xmlns:tools="http://schemas.android.com/tools"
 android:layout_width="match_parent"
 android:layout_height="match_parent"
 android:paddingBottom="@dimen/activity_vertical_margin"
 android:paddingLeft="@dimen/activity_horizontal_margin"
 android:paddingRight="@dimen/activity_horizontal_margin"
 android:paddingTop="@dimen/activity_vertical_margin"
 tools:context="com.viewrotationanimation_android_examples.com.MainActivity" >

 <TextView
 android:id="@+id/textView1"
 android:layout_width="200dp"
 android:layout_height="100dp"
 android:layout_alignParentTop="true"
 android:layout_centerHorizontal="true"
 android:layout_marginTop="52dp"
 android:background="#fca000"
 android:gravity="center"
 android:text="Large Text"
 android:textAppearance="?android:attr/textAppearanceLarge" />

 <Button
 android:id="@+id/button1"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:layout_below="@+id/textView1"
 android:layout_centerHorizontal="true"
 android:layout_marginTop="74dp"
 android:text="Click here to Create view rotation animation using objectanimator in android programmatically" />

</RelativeLayout>

Screenshots:

rotation-view

Create view rotation animation using objectanimator in android programmatically

Click here to download Create view rotation animation using objectanimator in android programmatically project.

Leave a Reply

Your email address will not be published. Required fields are marked *