Android scale animation
Scale the image 3 times bigger.
The first two params 1f, 3.0f says the width starts from the original length and ends with 3 times longer in length.
The secone two params 1f, 3.0f says the height starts from the original length and ends with 3 times longer in length.
The last two params ivWheel.getWidth() / 2.0f, ivWheel.getHeight() / 2.0f, indicates the povit point of the scaleing, in this case, the scaling goes from the center of the image and scale outwards.
ScaleAnimation scaleAnimation = new ScaleAnimation(1f, 3.0f, 1f, 3.0f, ivWheel.getWidth() / 2.0f, ivWheel.getHeight() / 2.0f); scaleAnimation.setDuration(3000); // scale to 3 times as big in 3 seconds scaleAnimation.setInterpolator(this, android.R.interpolator.accelerate_decelerate); ivWheel.startAnimation(scaleAnimation); scaleAnimation.setAnimationListener(new Animation.AnimationListener() { public void onAnimationStart(Animation animation) { Log.d("ScaleActivity", "Scale started..."); } public void onAnimationEnd(Animation animation) { Log.d("ScaleActivity", "Scale ended..."); } public void onAnimationRepeat(Animation animation) { } });
activity_scale.xml, the layout file for the scale animation demo.
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"> <Button android:id="@+id/btn_rotate" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="Scale" android:onClick="scale"/> <ImageView android:id="@+id/iv_wheel" android:layout_width="60dp" android:layout_height="60dp" android:layout_margin="100dp" android:layout_gravity="center" android:src="@drawable/wheel_image" /> </LinearLayout>
ScaleActivity.java, the activity file for the scale animation demo.
public class ScaleActivity extends AppCompatActivity { private ImageView ivWheel; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_scale); ivWheel = (ImageView) findViewById(R.id.iv_wheel); } public void scale(View v) { ScaleAnimation scaleAnimation = new ScaleAnimation(1f, 3.0f, 1f, 3.0f, ivWheel.getWidth() / 2.0f, ivWheel.getHeight() / 2.0f); scaleAnimation.setDuration(3000); // scale to 3 times as big in 3 seconds ivWheel.startAnimation(scaleAnimation); scaleAnimation.setAnimationListener(new Animation.AnimationListener() { public void onAnimationEnd(Animation animation) { Log.d("ScaleActivity", "Scale started..."); } public void onAnimationRepeat(Animation animation) { } public void onAnimationStart(Animation animation) { Log.d("ScaleActivity", "Scale ended..."); } }); } /** * Constructor to use when building a ScaleAnimation from code * * @param fromX Horizontal scaling factor to apply at the start of the * animation * @param toX Horizontal scaling factor to apply at the end of the animation * @param fromY Vertical scaling factor to apply at the start of the * animation * @param toY Vertical scaling factor to apply at the end of the animation * @param pivotX The X coordinate of the point about which the object is * being scaled, specified as an absolute number where 0 is the left * edge. (This point remains fixed while the object changes size.) * @param pivotY The Y coordinate of the point about which the object is * being scaled, specified as an absolute number where 0 is the top * edge. (This point remains fixed while the object changes size.) */ // public ScaleAnimation(float fromX, float toX, float fromY, float toY, // float pivotX, float pivotY) }
Search within Codexpedia
Custom Search
Search the entire web
Custom Search
Related Posts