Set animation time delay using objectanimator in android programmatically

How to apply animation delay time duration function in seconds so animation will starts after defining time.

Using setStartDelay() method we can set timing in seconds in android application so after completed that given time it will starts the animation process. So here is the complete step by step tutorial for Set animation time delay using objectanimator in android programmatically.

android-project-download-code-button

How to Set animation time delay using objectanimator in android programmatically.

Code for MainActivity.java file.

 package com.animationdelay_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.ImageView;

public class MainActivity extends Activity {

 ImageView img;
 Button button;
 ObjectAnimator objectanimator;
 @Override
 protected void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);
 setContentView(R.layout.activity_main);
 
 img = (ImageView)findViewById(R.id.imageView1);
 button = (Button)findViewById(R.id.button1);
 
 objectanimator = ObjectAnimator.ofFloat(img,"rotation",180);
 
 button.setOnClickListener(new View.OnClickListener() {
 
 @Override
 public void onClick(View v) {
 
 objectanimator.setDuration(3000);
 
 objectanimator.setStartDelay(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.animationdelay_android_examples.com.MainActivity" >

 <ImageView
 android:id="@+id/imageView1"
 android:layout_width="150dp"
 android:layout_height="150dp"
 android:layout_alignParentTop="true"
 android:layout_centerHorizontal="true"
 android:layout_marginTop="46dp"
 android:src="@drawable/abc_list_focused_holo" />

 <Button
 android:id="@+id/button1"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:layout_below="@+id/imageView1"
 android:layout_centerHorizontal="true"
 android:layout_marginTop="68dp"
 android:text="Click here to Set animation delay using objectanimator in android" />

</RelativeLayout>

Screenshots :

Set animation time delay using objectanimator in android programmatically

Click here to download Set animation time delay using objectanimator in android programmatically project.

Leave a Reply

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