I have to animate a drawer icon. The red circle needs to pop up in the same way as in the gif below. Any of the animation styles are fine, I only want to know if I can create an animation like these. Any thoughts?
I have searched the internet, but I haven't found anything so far.
You could try using the scale animation, for example, to get a similar effect of the pop animation in that gif you could do the following:
Create a file res/anim/bounce.xml:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="#android:anim/bounce_interpolator">
<scale xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="800"
android:fromXScale="1.5"
android:fromYScale="1.5"
android:pivotX="50%"
android:pivotY="50%"
android:toXScale="1"
android:toYScale="1" />
</set>
And then load the animation:
Animation bounceAnimation = AnimationUtils.loadAnimation(getActivity(), R.anim.bounce);
yourView.startAnimation(bounceAnimation);
I am new to android development. I want to create a splash screen with two text views. In this splash screen I want two transitions
1) Text View 1 transition from top to center
2) text View 2 transition from bottom to center
Both transitions should be performed at the same time
how to achieve this ?
Thanks,
Creat an xml file in your anim folder name bottom_to_top.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:duration="2000"
android:fillAfter="true"
android:fromYDelta="100%p"
android:toYDelta="0%p" />
</set>
and your oncreat you add this
TextView textview= (TextView) findViewById(R.id.textview);
Animation bottomToTop = AnimationUtils.loadAnimation(this, R.anim.bottom_to_top);
textview.startAnimation(bottomToTop);
and from top to bottom animation
create an xml file by name top_bottom.xml in your anim folder
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:duration="2000"
android:fillAfter="true"
android:fromYDelta="-100%p"
android:toYDelta="0%p" />
</set>
and place in java
TextView textview2= (TextView) findViewById(R.id.textview2);
Animation topTobottom = AnimationUtils.loadAnimation(this, R.anim.top_bottom);
textview2.startAnimation(topTobottom );
Hope this helps you
My imageview consists of circle wheel as shown in below pic.I want that wheel should start rotating as soon as user presses a start button and stop rotating when user presses stop button.Is it possible programmatically?If yes,how can i do that?
Create a file named clockwise_rotation.xml and put it into /res/anim Change the duration according to your needs.
<?xml version="1.0" encoding="utf-8"?>
<rotate
xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="3500"
android:fromDegrees="0"
android:interpolator="#android:anim/linear_interpolator"
android:pivotX="50%"
android:pivotY="50%"
android:repeatCount="infinite"
android:startOffset="0"
android:toDegrees="360"
/>
And make these two functions that you will be calling in your two buttons
private void startAnimation(){
Animation rotation = AnimationUtils.loadAnimation(getContext(), R.anim.clockwise_rotation);
mImageView.startAnimation(rotation);
}
private void stopAnimation(){
mImageView.clearAnimation();
}
I have 2 animations which are already working,
i want to fade my train + tween my train on the same time.
If I execute 1 of these lines it works.
But if I try to execute both it, only 1 will work..
I really can't find a solution here.
Maybe you can help?
final ImageView mytrain = (ImageView) findViewById(R.id.train);
final Animation traintween = AnimationUtils.loadAnimation(this,R.anim.treinanimation);
final Animation trainfade = AnimationUtils.loadAnimation(this,R.anim.trainfade);
mytrain.startAnimation(trainfade);
mytrain.startAnimation(trainntween);
I want mytrain to execute both animations..
Thank you for the help!
Use the AnimationSet class:
AnimationSet s = new AnimationSet(false);//false means don't share interpolators
s.addAnimation(traintween);
s.addAnimation(trainfad);
mytrain.startAnimation(s);
You need to use an AnimationSet, check out the docs. Just call addAnimation() for each Animation you want to play.
Can be done programatically using AnimatorSet class of android :
final AnimatorSet mAnimatorSet = new AnimatorSet();
mAnimatorSet.playTogether(
ObjectAnimator.ofFloat(img_view,"scaleX",1,0.9f,0.9f,1.1f,1.1f,1),
ObjectAnimator.ofFloat(img_view,"scaleY",1,0.9f,0.9f,1.1f,1.1f,1),
ObjectAnimator.ofFloat(img_view,"rotation",0 ,-3 , -3, 3, -3, 3, -3,3,-3,3,-3,0)
);
//define any animation you want,like above
mAnimatorSet.setDuration(2000); //set duration for animations
mAnimatorSet.start();
this example will start all the 3 animation on the target view(imgView) at same time ,you can also use playSequentially .....
For complete example check this out..
here is the example of all animation in a single xml file...
this will help you but first you should read the docs of AnimationSet
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<scale android:fromXScale="1.0" android:toXScale="3.0"
android:fromYScale="1.0" android:toYScale="3.0" android:pivotX="50%"
android:pivotY="50%" android:duration="5000" />
<set>
<alpha xmlns:android="http://schemas.android.com/apk/res/android"
android:fromAlpha="0.2" android:toAlpha="1.0" android:duration="3000" />
<rotate android:fromDegrees="0" android:toDegrees="-360"
android:toYScale="0.0" android:pivotX="50%" android:pivotY="50%"
android:startOffset="700" android:duration="4000" />
<!-- <translate android:fromXDelta="0%" android:toXDelta="0%" -->
<!-- android:fromYDelta="0%" android:toYDelta="100%" android:duration="3000" -->
</set>
</set>
you also can use the ImageSwitcher, i think this is better then AnimationSet in your case
I have an animation when you click on the red button on the right(area 2). When you click on the button there starts no animation. When you click on a part in area 1 the animation starts.
I don't know what I do wrong. Anyone a solution?
Animation: rotate.xml
<?xml version="1.0" encoding="utf-8"?>
<rotate xmlns:android="http://schemas.android.com/apk/res/android"
android:fromDegrees="0"
android:toDegrees="90"
android:pivotX="50%"
android:pivotY="50%"
android:duration="100"
android:fillAfter="true">
</rotate>
Java-code to start animation:
Animation animturn = AnimationUtils.loadAnimation(getContext(), R.anim.rotate);
v.setAnimation(animturn);
animturn.start();
Try with Invalidate() your View (v) after start() :
...
animturn.start();
v.Invalidate();