Android ScaleAnimation seems to ignore pivot - android

My custom ScaleAnimation seems to ignore its pivot point. Here is my super-call:
super(1.0f, widthFactor, 1.0f, heightFactor, pivotX, pivotY);
When I set pivotX to 1.0f and pivotY to 0.0f the top-left corner is fixed although it should be the top-right corner that is fixed.
Can you tell me what I am doing wrong?
Thank you!

maybe try with view.getLeft() and view.getTop() where view is the view on which you're trying to apply the animation instead of 1.0f and 0.0f? I'm a bit of android newbie myself, but using these has worked for me.

Related

How to change pivotX, pivotY in android?

I add view dynamically then use view.setX(100) and view.setY(100).
I want setPivotX and setPivotY for use scale animation.
I try ViewHelper.setPivotX, AnimatorProxy.setPivotX, view.setPivotX but not working. Some one help me
Be v a view,
v.setPivotX(0);
v.setPivotY(0);
Will set the pivot point at (0,0) (left-top)
v.setPivotX(v.getWidth() / 2);
v.setPivotY(v.getHeight() / 2);
Will set the pivot point at the view center
v.setPivotX(v.getWidth());
v.setPivotY(v.getHeight());
Will set the pivot point at the bottom right.
After setting the pivot point, you can then rotate the view to see it's working:
v.setRotationX((float)45);
v.setRotationY((float)45);

Circular scale animation

I'm trying to achieve an animation which scales over a view like this:
At the moment I'm using a scale animation loaded from xml:
This in action looks like this:
It scales more like a square.
I was using ObjectAnimator/ValueAnimator with properties before.
Some devices had specific problems with measuring heights for scaling so I reverted to using xml definitions.
Does anyone have any clue how to achieve the above?
you must define programmatically you ScaleAnimation.
first get radius of your circle(ImageView) at first position(before start Animation).
for get radius you can get width of your imageview and then division to 2.
second you must get width and height of your square.
third do it :
anim_to = (width_square + height_Square) / radius_circle;
finally set "anim_to" to your ScaleAnimation and start animation like this:
ScaleAnimation my_reveal = new ScaleAnimation(1,anim_to, 1,anim_to, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
my_reveal.setInterpolator(new DecelerateInterpolator());
my_reveal.setDuration(500);
my_circle.startAnimation(my_reveal);
sorry for my bad ENG ;)

android objectanimator scaleX only in one direction

I am using ObjectAnimator and cant figure out how to scale in x axe only in one direction for example to right side. Because when im scaling it scales both ways and then my ImageView is out of screen. I know i could add transitionX to prevent going off-screen but a better solution would be scaling in one direction.
ObjectAnimator headAnim = ObjectAnimator.ofFloat(imageHead, "scaleX", 1f, 1.5f);
headAnim.setDuration(1000);
headAnim.start();
Just set the pivot point of the View, using View.setPivotX() and View.setPivotY(). Set it to 0,0 to achieve the effect you want.
The param of View.setPivotX/Y is a float value. It is the absolute value of width or height, not the percent.

Android Image View Animation leaving behind trail

I am animating an ImageView from the center of the screen to the top-left using an Animation Set.I am Translating and Scaling the View.
Heres the code snippet.
AnimationSet tempAnimation=new AnimationSet(true);
TranslateAnimation anim = new TranslateAnimation( 0,xPos, 0, yPos );
anim.setFillAfter( true );
anim.setFillEnabled(true);
ScaleAnimation scaleanimation = new ScaleAnimation(1, (float)0.22, 1, (float)0.22, Animation.RELATIVE_TO_SELF, (float)0.5, Animation.RELATIVE_TO_SELF, (float)0.5);
scaleanimation.setDuration(1000);
scaleanimation.setFillEnabled(true);
scaleanimation.setFillAfter(true);
tempAnimation.addAnimation(scaleanimation);
tempAnimation.addAnimation(anim);
tempAnimation.setDuration(1000);
// This takes care that the ImageViews stay in their final positions after animating .
tempAnimation.setFillEnabled(true);
tempAnimation.setFillAfter(true);
mimageView.startAnimation(tempAnimation);
So,the problem is that it is leaving behind a trail /previous positions for just a brief moment.But it doesnt look good or smooth.I have noticed that if I use only 1 animation it is fine but using the animation set causes the trail.Are there any tips to avoid this?
Cheers
Found the answer eventually at https://code.google.com/p/android/issues/detail?id=22151.
Scale and Translation Animations have a problem on Android 2.3 .The simplest way to fix this is to add a small transparent padding around the image.In the code shown above,Just add
mimageView.setPadding(1,1,1,1);
Works like a charm!

pivotX and PivotY on ScaleAnimation has no effect

I'm trying to scale a View equivalent to the right and left from center of a View using ScaleAnimation . Whatever values I set for pivotX and PivotY it always scale in the same way (like right edge appears to be scaling keeping left edge constant). Below is the code I used to initialize the ScaleAnimation. Can anyone please let me know, if Im doing anything wrong?. Thanks.
final ScaleAnimation scaleAnim = new ScaleAnimation(1.0f, 2.0f, 1.0f, 1.0f,
Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
Initialing the anim solved the problem.
I just used the below to code to initialise it.
anim.initialize(/* animate view */child.getWidth(),
child.getHeight(),
/* parents view */ this.getWidth(),
this.getHeight());

Categories

Resources