I am currently doing an animation from the material spec design, now I want to enable to do a point of origin animation which is showed here:
Sample Animation Link
How can I do that animation of pre lollipop? Is there a way doing it in pre-lollipop devices?
I've achieved this point of Origin creating a XML based approach and applying it to your custom Theme.
Create anim/anim_in.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<scale
android:interpolator="#android:anim/accelerate_decelerate_interpolator"
android:fromXScale="0.0"
android:toXScale="1.0"
android:fromYScale="0.0"
android:toYScale="1.0"
android:fillAfter="false"
android:startOffset="200"
android:duration="200"
android:pivotX = "100%"
android:pivotY = "100%"
/>
<translate
android:fromYDelta="50%"
android:toYDelta="0"
android:startOffset="200"
android:duration="200"
/>
</set>
Then Create anim/anim_out.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<scale
android:interpolator="#android:anim/accelerate_decelerate_interpolator"
android:fromXScale="1.0"
android:toXScale="0.0"
android:fromYScale="1.0"
android:toYScale="0.0"
android:fillAfter="false"
android:duration="200"
android:pivotX = "100%"
android:pivotY = "100%"
/>
<translate
android:fromYDelta="0"
android:toYDelta="50%"
android:duration="200"
/>
</set>
This animation origin pops a window or dialog fragment from right bottom corner of the screen. Modify pivotX and pivotY to change the location of the origin
Define this windows animation in your style.xml
<style name="InOut.Window" parent="#android:style/Animation.Activity">
<item name="android:windowEnterAnimation">#anim/anim_in</item>
<item name="android:windowExitAnimation">#anim/anim_out</item>
</style>
Lastly apply this animation to all the window for your custom Theme that you would have created.
<style ....>
...
<item name="android:windowAnimationStyle">#style/InOut.Window</item>
</style>
Related
I wanted to create a button that changes it's colour when clicked on it . Also the button should pop out a little and then pop back in or bounce .
I already checked out the post related to this but I'm sorry to say that it didn't work out for me.
Also it will be really helpful if you mention the entire part of the code and not the necessary parts. Thanks a lot in Advance :)
I can't post the image of the code I typed cos of less reputation . So sorry about that.
for just button color change only you can always use Selector drawable as a back ground for example like this!
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="false">
<shape android:shape="rectangle">
<solid android:color="#color/colorPrimary"></solid>
<corners android:radius="20dp"></corners>
</shape>
</item>
<item android:state_pressed="true">
<shape android:shape="rectangle">
<solid android:color="#000"></solid>
<corners android:radius="10dp"></corners>
</shape>
</item>
//--------------------------------------------------------------------------//
for animation like to raise up you can give a feel of size animation or for free form moving your should use Translate anim
here is the way!
1: put a new res folder called anim and right click on it which will let you make the anim resource and there you make one like "translate_anim.xml" and put this in it
In order to change position of object use tag. It uses fromXDelta, fromYDelta for X-direction and toXDelta, toYDelta attributes for Y-direction. move.xml
<?xml version="1.0" encoding="utf-8"?>
<set
xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="#android:anim/linear_interpolator"
android:fillAfter="true">
<translate
android:fromXDelta="0%p"
android:toXDelta="75%p"
android:duration="800" />
</set>
And then in java you have to go and set up the animation using this
Animation translater = AnimUtils.loadAnimation(getApplicationContext,R.anim.translate_anim);
Button btnMoving = findViewbyId(R.id.btn_moving);
btnMoving.startAnimation(btnMoving);
here is the resource anim file for scale UP.
slide_up.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:fillAfter="true" >
<scale
android:duration="500"
android:fromXScale="1.0"
android:fromYScale="1.0"
android:interpolator="#android:anim/linear_interpolator"
android:toXScale="1.0"
android:toYScale="0.0" />
</set>
I need to make an imageview with rotation feature. So I looked at the android developers site. And used their codes. But somehow I get an error.
Error:java.lang.ClassCastException: android.graphics.drawable.StateListDrawable cannot be cast to android.graphics.drawable.AnimationDrawable
I have these codes:
ImageView refresh = (ImageView)findViewById(R.id.refresh_devices_button);
refresh.setBackgroundResource(R.drawable.spin_animation); // The IDE says that it may produce null pointer exception
AnimationDrawable frameAnimation = (AnimationDrawable) refresh.getBackground();
frameAnimation.start();
In spin_animation.xml:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<animation-list android:id="#+id/selected" android:oneshot="false">
<item android:drawable="#drawable/scan_1" android:duration="50" />
<item android:drawable="#drawable/scan_2" android:duration="50" />
<item android:drawable="#drawable/scan_3" android:duration="50" />
<item android:drawable="#drawable/scan_4" android:duration="50" />
<item android:drawable="#drawable/scan_5" android:duration="50" />
</animation-list>
</selector>
Please help me. From android's site I get the codes but their codes does not work. Maybe the problem is with my spin_animation.xml file.
refresh.getBackground returns StateListDrawableI think.
You can use something like this
ImageView splash = (ImageView) view.findViewById(R.id.imageView);
RotateAnimation anim = new RotateAnimation(0f, 360f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
anim.setInterpolator(new LinearInterpolator());
anim.setRepeatCount(Animation.INFINITE);
anim.setDuration(500);
// Start animating the image
splash.startAnimation(anim);
I have a rotation animation for my ImageView. You can try with this code:
First create your xml for rotation animation in anim directory :
rotation_animation.xml :
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<rotate
android:duration="400"
android:fromDegrees="0"
android:pivotX="50%"
android:pivotY="50%"
android:startOffset="0"
android:toDegrees="360" />
</set>
After that in your Java class (activity or fragment) add this :
Animation rotationAnimation = AnimationUtils.loadAnimation(this, R.anim.rotation_animation);
yourImageView.startAnimation(rotationAnimation);
Now you are ready. Happy codding :)
Use below code and import below class as well.
import android.graphics.drawable.AnimationDrawable;
private AnimationDrawable mAnimation;
private ImageView mAnimLogo;
mAnimLogo = (ImageView) findViewById(R.id.loading_image);
mAnimation = (AnimationDrawable) mAnimLogo.getDrawable();
mAnimation.start();
With this line :
AnimationDrawable frameAnimation = (AnimationDrawable) refresh.getBackground();
you are trying to cast a StateListDrawable to an AnimationDrawable which throws the exception.
Nice and simple :
refresh.animate().rotation(360).setDuration(...);
rotates your view to 360 Degrees clockwise in ... ms.
Or
refresh.animate().rotationBy(360).setDuration(...);
rotates the view BY 360 degrees.
Check out ViewPropertyAnimator for different kinds of animations you can code in one line.
Rotation Animation to imageview
`RotateAnimation anim = new RotateAnimation(0f, 350f, 15f, 15f);
anim.setInterpolator(new LinearInterpolator());
anim.setRepeatCount(Animation.INFINITE);
anim.setDuration(700);
// Start animating the image
final ImageView splash = (ImageView) findViewById(R.id.splash);
splash.startAnimation(anim);
// Later.. stop the animation
splash.setAnimation(null);`
I found that android site is okay. The problem was with my xml file.
I had this code
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<animation-list android:id="#+id/selected" android:oneshot="false">
<item android:drawable="#drawable/scan_1" android:duration="50" />
<item android:drawable="#drawable/scan_2" android:duration="50" />
<item android:drawable="#drawable/scan_3" android:duration="50" />
<item android:drawable="#drawable/scan_4" android:duration="50" />
<item android:drawable="#drawable/scan_5" android:duration="50" />
</animation-list>
</selector>
Instead of the above code I used the following code. I had to remove the<selector> tags.
<?xml version="1.0" encoding="utf-8"?>
<animation-list
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/selected" android:oneshot="false">
<item android:drawable="#drawable/scan_1" android:duration="50" />
<item android:drawable="#drawable/scan_2" android:duration="50" />
<item android:drawable="#drawable/scan_3" android:duration="50" />
<item android:drawable="#drawable/scan_4" android:duration="50" />
<item android:drawable="#drawable/scan_5" android:duration="50" />
</animation-list>
I want to know how to make this kind of animation in android ( The same in Battery Doctor app ).
I found a way to do this using two green images with an oppacity of 50% one behind the other and another one on the front to hide the unwanted content ( The circle ),I animate the first green image by XML using the code below
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<rotate
android:duration="1850"
android:fromDegrees="-4"
android:pivotX="50%"
android:pivotY="50%"
android:repeatCount="infinite"
android:repeatMode="reverse"
android:interpolator="#android:anim/linear_interpolator"
android:toDegrees="4" />
<translate
android:fromXDelta="0"
android:toXDelta="0"
android:fromYDelta="0"
android:toYDelta="1"
android:repeatCount="infinite"
android:repeatMode="reverse"
android:interpolator="#android:anim/linear_interpolator"
android:duration="1500" />
</set>
And the second green one by using this:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<rotate
android:duration="1800"
android:fromDegrees="-1"
android:pivotX="50%"
android:pivotY="50%"
android:repeatCount="infinite"
android:repeatMode="reverse"
android:interpolator="#android:anim/linear_interpolator"
android:toDegrees="1" />
<translate
android:fromXDelta="80"
android:toXDelta="-4"
android:fromYDelta="-1"
android:toYDelta="1"
android:repeatCount="infinite"
android:repeatMode="reverse"
android:interpolator="#android:anim/linear_interpolator"
android:duration="1500" />
</set>
But how can I create the view programatically ?I want to set the level dynamically from code. for example myView.setLevel(45);
I have finally found a library: WaveView
https://github.com/john990/WaveView
Edit
This library https://github.com/gelitenight/WaveView also does the same thing with more features. You can :
Shift the wave horizontally.
Set water level.
Set vertical size of wave.
Set horizontal size of wave.
I have Two Activities A and B
A is starting B like
Intent i = new Intent();
i.setClass(A.this, B.class);
startActivity(i);
overridePendingTransition(R.anim.right_slide_in, R.anim.down_slide_out);
finish();
where
R.anim.right_slide_in is
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" >
<translate
android:fromXDelta="+100%p"
android:toXDelta="0"
android:duration="700"
/>
</set>
and
R.anim.down_slide_out is
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
<translate
android:fromYDelta="0"
android:toYDelta="+100%p"
android:duration="700" />
</set>
This work great. B comes sliding from right and A goes out sliding down.
Problem is during this transition. A Blank Screen appears as background of whole app
How to avoid that ?
Any help would be appreciated
Try using an application theme (e.g., <application android:theme="#style/MyTheme">) that sets the android:windowBackground attribute to a drawable, such as:
<resources>
<style name="MyTheme" parent="android:Theme">
<item name="android:windowBackground">#drawable/app_background</item>
</style>
</resources>
Not Possible As far As Application Layer is Concerned.
Try this.
move_to_left.xml
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:fillAfter="true"
android:interpolator="#android:anim/linear_interpolator" >
<translate
android:duration="800"
android:fromXDelta="100%p"
android:toXDelta="0%p" />
</set>
move_to_right.xml
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:fillAfter="true"
android:interpolator="#android:anim/linear_interpolator" >
<translate
android:duration="800"
android:fromXDelta="0%p"
android:toXDelta="-100%p" />
</set>
startActivity(recipeCategoriesIntent);
overridePendingTransition(R.anim.move_to_left, R.anim.move_to_right);
I am having trouble applying an animation to a View. I am trying to load the animation from inside the constructor of a CursorAdapter, so I can set it later assign it to certain children in the list.
In the constructor I have :
shineAnimation = AnimationUtils.loadAnimation(ctx, R.anim.news_list_item_shine);
the animation is in my res/anim dir
<?xml version="1.0" encoding="utf-8"?>
<animation-list xmlns:android="http://schemas.android.com/apk/res/android" android:oneshot="true">
<item android:drawable="#drawable/shine1" android:duration="200" />
<item android:drawable="#drawable/shine2" android:duration="200" />
<item android:drawable="#drawable/shine3" android:duration="200" />
<item android:drawable="#drawable/shine4" android:duration="200" />
<item android:drawable="#drawable/shine5" android:duration="200" />
</animation-list>
I'm getting an exception :
Unknown animation name: animation-list
Help would be much appreciated
Thanks
S
I don't think you load AnimationDrawables via AnimationUtils. AnimationDrawable is a Drawable more than it is an Animation. Try this sample code from the SDK guide.
ImageView rocketImage = (ImageView) findViewById(R.id.rocket_image);
rocketImage.setBackgroundResource(R.anim.rocket_thrust);
rocketAnimation = (AnimationDrawable) rocketImage.getBackground();