android objectanimator scaleX only in one direction - android

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.

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);

Animate image size

I would like to have an image "bump" (or change its size) according to music. I don't need the music detect side, I just need a way to resize the image dymaically and according to an animation. What is the best way to do this?
If you're using at least API 11 and want to animate it smoothly, you can use an ObjectAnimator to animate various changes to the properties of a View. For example:
ObjectAnimator oa = ObjectAnimator.ofFloat(myView, View.SCALE_X, 1.0, 1.25);
oa.setDuration(25); //how long the animation lasts in ms, probably short for your purposes
oa.start();
This will scale the X size of the view myView from the default (1.0) to slightly larger (1.25). You will then need to do the same for the SCALE_Y property. Note that you will probably want to keep track of the current scale value so that your next animations look nice. For example:
float currentScale = 1.0;
...
void scaleMyView(float newScale) {
ObjectAnimator oa = ObjectAnimator.ofFloat(myView, View.SCALE_X, currentScale, newScale);
oa.setDuration(25);
oa.start();
currentScale = newScale;
}
See also the documentation on ObjectAnimators if you need more info. Hope this helps!
Every View has setScaleX and setScaleY methods. I believe you can use it for this. As far as syncing it to the music, that depends on the way you're playing it.
There is greate animation library for Android.
https://github.com/daimajia/AndroidViewAnimations
https://github.com/2359media/EasyAndroidAnimations

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 ;)

SubsamplingScaleImageView initial zoom and position

I am using Dave Morrissey's gorgeous library https://github.com/davemorrissey/subsampling-scale-image-view , especially SubsamplingScaleImageView and I want image inside this view initialised with scale 100% and centered. There is method setScaleAndCenter(float, PointF), first parameter is scale, I set it to 1f, the second is point describing center but I don't know which values it should have.
My image has 2000x3000 px, I was trying set x and y of center point to 1000 and 1500, also I was trying something like 0.5f, 50 (percents) but it doesn't work.
How to calculate values for setScaleAndCenter(float, PointF) in order to center image?

Transform and scale animation on a View

I have a linear layout with three images in it. On the click of any ImageView I want to animate the whole linear layout. The animation consists of two animations - scale and transform. I don't know how to perform this animation.
This is what I want -
Image 1 - Before Animation
Image 2 - After Animation
I want to not only animate the View but actually shift the view to its new location with animation. After animation I should be able to click the Images at their new locatoin not the old location.
How can I perform this? Please help me out.
I used nineoldandroids library to achieve this animation. I used two animation: translation and scaling.
Translation:
ObjectAnimator.ofFloat(frameCategoryScroll, "translationY", 0, -yValue).setDuration(600).start();
yValue is the the value in y axis upto which I want to translate.
Scaling:
ObjectAnimator.ofFloat(frameCategoryScroll, "scaleX", 1.0f, 0.6f).setDuration(600).start();
ObjectAnimator.ofFloat(frameCategoryScroll, "scaleY", 1.0f, 0.6f).setDuration(600).start();

Categories

Resources