Android zooms animation to make ImageView run
•
Android
In my application, I'm dynamically creating an ImageView and setting it to a constant x, y position, and then zooming on it. But I'm not sure why it runs (ImageView changes its position)
@H_419_5@ <?xml version="1.0" encoding="utf-8"?> <set android:shareInterpolator="false" xmlns:android="http://schemas.android.com/apk/res/android"> <scale android:interpolator="@android:anim/accelerate_decelerate_interpolator" android:fromXScale="1.0" android:toXScale="2.5" android:fromYScale="1.0" android:toYScale="2.5" android:pivotX="50%" android:pivotY="50%" android:fillAfter="false" android:duration="1000" /> <alpha android:fromAlpha="1" android:toAlpha="0" android:duration="1000" /> </set>
But I want it to be in the same position and need to scale from a smaller size to a larger size. Please help with this, I'm not sure I'm wrong
@H_419_5@final ImageView rippleImageView = new ImageView(context); rippleImageView.setX(X); rippleImageView.setY(Y); rippleImageView.setImageBitmap(image); ((ViewGroup)(findViewById(R.id.rippleEffectView)).addView(rippleImageView, 0); Animation a = AnimationUtils.loadAnimation(context, R.anim.scale_up); a.setAnimationListener(new Animation.AnimationListener() { @Override public void onAnimationStart(Animation animation) { } @Override public void onAnimationEnd(Animation animation) { ((ViewGroup) rippleImageView.getParent()).removeView(rippleImageView); } @Override public void onAnimationRepeat(Animation animation) { } }); rippleImageView.startAnimation(a);
The layout file is very simple,
@H_419_5@<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" tools:context=".MainActivity"> <Button android:id="@+id/button" android:layout_width="80dp" android:layout_height="80dp" android:layout_centerInParent="true" /> <RelativeLayout android:id="@+id/rippleEffectView" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_centerHorizontal="true" android:layout_margin="5dp"> </RelativeLayout> </RelativeLayout>
At present, I have the following
I hope both circles must be in the same position
resolvent:
Finally, I successfully completed the work through the following two steps
I have changed relativelayout to absolutelayout. In the layout file
@H_419_5@<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" tools:context=".MainActivity"> <Button android:id="@+id/button" android:layout_width="80dp" android:layout_height="80dp" android:layout_centerInParent="true" /> <AbsoluteLayout android:id="@+id/rippleEffectView" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_centerHorizontal="true" android:layout_margin="5dp"> </AbsoluteLayout> </RelativeLayout>
I don't know why setx () and sety () don't work properly, but changing layout parameters is valid
@H_419_5@ final ImageView rippleImageView = new ImageView(context); LayoutParams params = new AbsoluteLayout.LayoutParams(200, 200, X, Y); rippleImageView.setParams(params); rippleImageView.setImageBitmap(image); ((ViewGroup)(findViewById(R.id.rippleEffectView)).addView(rippleImageView, 0); Animation a = AnimationUtils.loadAnimation(context, R.anim.scale_up); a.setAnimationListener(new Animation.AnimationListener() { @Override public void onAnimationStart(Animation animation) { } @Override public void onAnimationEnd(Animation animation) { ((ViewGroup) rippleImageView.getParent()).removeView(rippleImageView); } @Override public void onAnimationRepeat(Animation animation) { } }); rippleImageView.startAnimation(a);
Now my output is
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码