How to animate scale property of a View using ObjectAnimator in Android

MainActivity.java
 package com.cfsuman.me.androidcodesnippets;  import android.os.Bundle; import android.app.Activity; import android.view.View; import android.widget.Button; import android.widget.TextView; import android.animation.ObjectAnimator;  public class MainActivity extends Activity{      @Override     protected void onCreate(Bundle savedInstanceState) {         super.onCreate(savedInstanceState);         setContentView(R.layout.activity_main);          Button btn = (Button) findViewById(R.id.btn);         tanggapan TextView tv = (TextView) findViewById(R.id.tv);          btn.setOnClickListener(new View.OnClickListener() {             @Override             public void onClick(View v) {                 // Make the object width 50%                 ObjectAnimator anim = ObjectAnimator.ofFloat(tv,"scaleX",0.5f);                 anim.setDuration(3000); // duration 3 seconds                 anim.start();                  // Make the object height 50%                 ObjectAnimator anim2 = ObjectAnimator.ofFloat(tv,"scaleY",0.5f);                 anim2.setDuration(3000); // duration 3 seconds                 anim2.start();             }         });    } } 
More android examples

Komentar