I have image which is symmetrical and I want to move it infinitly from right to left smoothly. I tried to use TranslateAnimation but first I have to properly set my image which is quite difficult mainly because this image is using all screen width and I should set negative margins. Are there any other solution? And is there a possibility to move image without moving ImageView?
Finally I made it by my own and the solution is to put 2 images on each other and then measure screen width and use 2 TranslateAnimation, one from screen width to 0 and second one from 0 to -screen width:
TranslateAnimation anim = new TranslateAnimation(0, -screenWidth, 0, 0);
TranslateAnimation anim2 = new TranslateAnimation(screenWidth, 0, 0, 0);
anim.setDuration(5000);
anim.setRepeatCount(Animation.INFINITE);
anim.setInterpolator(new LinearInterpolator());
anim2.setDuration(5000);
anim2.setRepeatCount(Animation.INFINITE);
anim2.setInterpolator(new LinearInterpolator());
backgroundOverlayImage.startAnimation(anim);
backgroundOverlayImage2.startAnimation(anim2);
I think this is what you are trying to do:
TranslateAnimation anim = new TranslateAnimation(0, -1000, 0, 0);
anim.setDuration(1500);
anim.setFillAfter(true);
anim.setRepeatCount(0);
anim.setInterpolator(this, Android.Resource.Animation.LinearInterpolator);
Edit:
at the end don't forget imageView.startAnimation(anim);
Though you got answer, try this repository, this will solve all your queries regarding slides and also will add custom animation to your views!
Related
Im trying to animate two Buttons from a point (1st button). On Click of the first button, that button is set to INVISIBLE/GONE and two other button are shown. I am trying to pass the X and Y values of the View(1st button) as follows:
button.getX();
button.getY();
but im not getting the exact center (of 1st button).
Im trying to send those X and Y values to the animation but both the buttons (button2, button3) are coming side by side.. I want them to overlap as the point where they start animation is same. Im using the following code for the animation:
AnimatorSet animations = new AnimatorSet();
Animator xAnim = ObjectAnimator.ofFloat(button, "translationX", finalXValue);
xAnim.setDuration(3000);
Animator yAnim = ObjectAnimator.ofFloat(button, "translationY", finalYValue);
yAnim.setDuration(3000);
Animator alphaAnim = ObjectAnimator.ofFloat(button, "alpha", finalAlphaValue);
alphaAnim.setDuration(alphaDuration);
//Play all the animations together
animations.play(xAnim).with(yAnim).with(alphaAnim);
I want the animation to be like this
#Deev Thanks thats really helped but the code im using has no start position
TranslateAnimation tanim_stay = new TranslateAnimation(
TranslateAnimation.ABSOLUTE, getIntent().getFloatExtra("ButtonX", 0) - btn_armed_stay.getWidth(),
TranslateAnimation.ABSOLUTE, btn_armed_stay.getX()+ (btn_armed_stay.getWidth()/2),
TranslateAnimation.ABSOLUTE, -getIntent().getFloatExtra("ButtonY", 0),
TranslateAnimation.ABSOLUTE, btn_armed_stay.getY()+ (btn_armed_stay.getHeight()/2));
Im using this code for the start and end position of the animation but how to add another animation to the current Translate animation.. I want to add Alpha animation to this Translate animation..
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!
I want to be able to do this: the TextView to change its size (to get bigger) and to change its alpha value (from invisible to become visible). All of this using Animation and have this changes happen at the same time.
For that purpose I come up with this code:
AnimationSet set = new AnimationSet(true);
Animation animation = new AlphaAnimation(0.0f, 1.0f);
animation.setDuration(2000);
animation.setStartOffset(300);
animation.setFillAfter(true);
set.addAnimation(animation);
animation = new ScaleAnimation(1.0f, 2.0f, 1.0f, 2.0f);
animation.setDuration(2000);
animation.setStartOffset(300);
animation.setFillAfter(true);
set.addAnimation(animation);
text.startAnimation(set);
The problem with this is that I want this transformation to remain. But the textView keeps coming back to its original size at the end. (But it remains visible - alpha = 1.0f). Am I doing something wrong? Please, if someone knows how can I make this work, help me. Thank u in advance!
I've found an answer for the problem five minutes after actually posting it. You should not define setFillAfter for the individual animations that you define in the animation set. You should only define setFillAfter ON the animation set itself
I'm still having problem with the most basic need.
I wanna have 2 buttons: one runs a tween animation that moves an image 50 pixels, the other button runs a frame by frame animation on that image.
once the tween animation is done, the frame by frame animation runs in the wrong location. weird.
I'm using FillAfter/FillEnabled,
the code to run the tween animation is a basic
TranslateAnimation(0, 50, 0 , 0) with the fill after and fillEnabled = true.
the frame by frame code is
image.setImageDrawable(getResources().getDrawable(resourceId));
((AnimationDrawable) image.getDrawable()).start();
help will be appreciated.
Cheers
The only way I found of doing it is
first you move your imageview position, using setLayoutParams with the new margins,
and only then you start the TranslateAnimation using (-x, -y, 0, 0) so for my specific case in the question, here is my code:
TranslateAnimation tweenAnim = new TranslateAnimation(-1 * XStep, -1 * YStep , 0, 0);
tweenAnim.setDuration(number_of_steps * 750);
tweenAnim.setFillAfter(true);
tweenAnim.setFillEnabled(true);
tweenAnim.setInterpolator(new LinearInterpolator());
//layout positioning
lp.leftMargin += XStep;
lp.bottomMargin += YStep;
imageView.setLayoutParams(lp);
Log.v(TAG, "leftMargin=" + lp.leftMargin);
Log.v(TAG, "bottomMargin=" + lp.bottomMargin);
imageView.startAnimation(tweenAnim);
This was a huge pain. seriously.
thanks for http://www.clingmarks.com/?p=400 I was able to overcome it.
I am using following code for rotating an image
RotateAnimation anim1 = new RotateAnimation(0, 360, 8, 70);
anim1.setRepeatCount(0);
anim1.setDuration(18000);
anim1.setFillAfter(true);
img7.startAnimation(anim1);
After that I am using another animation
RotateAnimation anim1 = new RotateAnimation(360, 0, 8, 70);
anim1.setRepeatCount(0);
anim1.setDuration(18000);
anim1.setFillAfter(true);
img7.startAnimation(anim1);
When I am using both the animations without any action listener one of them will work....What I actually want, is at the end of the first animation, for the second animation to start...Can anybody help me to do this?
I am not using any XML code for animation.
Why won't you use Animation.AnimationListener for the first animation (setAnimationListener()) and launch the second when the first one finishes?
I think AnimatorSet was designed for this. Demo in the sdk.