I have an ImageView and I want to translate it to a random spot on the screen:
TranslateAnimation anim = new TranslateAnimation(0,100,0,100);
anim.setDuration(2000);
img.startAnimation(anim);
This works fine. But I want to have a clickable ImageView during the whole animation.
At this moment it only works at the beginning and at the end.
I think you have to use Animator class and not Animation class because when using TranslateAnimation, you are animating a image of a view and not a View it self.
I think this is explained somewhere there
http://android-developers.blogspot.com/2011/02/animation-in-honeycomb.html
And on the next page
Related
I have a view. I will set the view left out of the screen. Now I want to animate a slide from left to the screen on this view. How can do this in Android?
This is my View
<androidx.constraintlayout.widget.ConstraintLayout
android:id="#+id/mView"
android:layout_width="200dp"
android:layout_height="140dp"
android:layout_gravity="center_vertical|end">
This is the sample code for move a textview with animation from x position as 0 to centre of the screen width.
ObjectAnimator textViewAnimation= ObjectAnimator.ofFloat(textView,"X",0f,width/2);
textViewAnimation.setDuration(2000);
textViewAnimation.start();
You can check this tutorial about animations https://github.com/codepath/android_guides/wiki/Animations
Here is the example code to move a textview in x-axis 100 points. You can animate your own view like this.
ObjectAnimator animation = ObjectAnimator.ofFloat(textView, "translationX", 100f);
animation.setDuration(1000);
animation.start();
I have some imageviews which I am translating using
ObjectAnimator moveY = ObjectAnimator.ofFloat(stone, "y", catPos[1] );
When it translates to the specified position,and there is already another image view there, it places itself under the imageview. I want the newly moved imageview to be seen on top. How can i do that?
Adding code bringToFont() worked.
In my Android app, I have a TextView with a white background. When it is clicked, its background will change to a .png picture of some icon by calling setBackgroundResource(R.drawable.icon) on the TextView. This works as intended, but the change is rather abrupt. I would like to make the icon appear more gradually; when the TextView is clicked, a tiny version of the icon should appear in the center of the TextView and then immediately expand and fill out the entire TextView. I believe the best way to do this would be by using an animation, which of the available animation types in Android are best for this task?
In case it is not clear what I mean, I drew a sketch to illustrate. The second sequence shows how the code works right now, the first shows how I would like it to be.
So, I managed to get the effect you want with an ImageView, using ScaleAnimation. Here's what you have to do:
First, our XML ImageView:
<ImageView
android:id="#+id/scale_anim"
android:layout_width="60dp"
android:layout_height="60dp"
android:background="#android:color/white" />
It has fixed dimensions and a white background.
The animation will start with one click with this, inside your onCreate() method:
ImageView starImageView = (ImageView) findViewById(R.id.scale_anim);
starImageView.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
ScaleAnimation starScaleAnimation =
new ScaleAnimation(0.3f, 1f, 0.3f, 1f,
ScaleAnimation.RELATIVE_TO_SELF, 0.5f,
ScaleAnimation.RELATIVE_TO_SELF, 0.5f);
starScaleAnimation.setDuration(500);
((ImageView) v).setImageResource(R.drawable.star);
ScaleAnimation scaleAnim = starScaleAnimation;
v.startAnimation(scaleAnim);
}
});
We are applying a scale animation on the ImageView that stars with 30% of the original size and scales to 100% of its size, from its center point. The duration of this animation is half a second. All these parameters can be changed.
Every time you click the ImageView, your drawable will be applied and the animation will start.
Try this way if it solve yours.
Create an ImageView (X) above your original ImageView (A) - same size and same place as (A)
Animate (X) with ObjectAnimator, listen for the onAnimationEnd call and set the (A)'s background. Then remove (X).
Hope this will help.
Is there an easy possibility to change an image in an imageview and let the imagechange animate by swiping out for example to the right and let the new image swipe in from left or swipe out downside and swipe in from upside?
You can do that easily by using translate-animation. First, prepare a translate animation object that specifies say sliding out to the right by 200 pixels. Set the animation on the imageview and start the animation. Once the animation ends (set animation listener on it), change the imageview to your new image and again use a translate animation to slide it in from the left, in the same way.
I have these 2 pictures:
and I´m trying to make an animation of them. I want to show the first picture (the one without wheels) and then the one with booth wheels. It shall be looking like the wheels have appeared, because the position will not be changed and the car shall not disappear. So I tried to use fade-in effect, because if I just "reload" my xml layout, it doesnt look very good.
I found many tutorials, but none of them did solve my problem. My question is: Does anybody know, how to do that?
use FrameLayout to stack two ImageView always show your first picture the one without weels and use any action listener to triger the animation on second ImageView using AlphaAnimation..
Animation animation = new AlphaAnimation(0.0f, 1.0f);
animation.setDuration(1000); // anim duration in milli second
animation.setRepeatCount(0); // 0 no repeat
animation.setFillAfter(true);
iv.startAnimation(animation); // iv is your imageview