Not getting proper frame by frame animation - android

This is my code and resultpage1 and resultpage2 is my .jpg file.This is my background image and i need this to be animated .The image is full of hearts and i need the hearts to fall down from top.Background image is added succesfully but animation is not proper.The hearts while falling are shaking rather falling down slowly.I need the hearts to fall down slowly instead shaking.Iam new to android.Please help
<?xml version="1.0" encoding="utf-8"?>
<animation-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:drawable="#drawable/resultpage1"
android:duration="50"/>
<item
android:drawable="#drawable/resultpage2"
android:duration="50"/>
<item
android:drawable="#drawable/resultpage3"
android:duration="50"/>
<item
android:drawable="#drawable/resultpage4"
android:duration="50"/>
<item
android:drawable="#drawable/resultpage5"
android:duration="50"/>
</animation-list>

You should be using optimized png images for this. You also are going to need more than two images in most cases. Your animation will almost have a strobe affect if you only use two images. Here is more information regarding different xml animations
http://www.androidhive.info/2013/06/android-working-with-xml-animations/

Related

Image Button change size onClick

On Android Studio I made an image perform like a button. Though what I can't find anywhere is how do I make it so when I click on the image aka the button it becomes a bit smaller and when you release it comes back to original size. Ik that onClick you can perform functions and activities and what not but how do I change the actual button image so as I'm holding down the click button it gets smaller and when i release it comes back to its original size.
You can use selectors to achieve that. For example define this in your drawable folder:
selector_state_xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="#drawable/button_bg_selected" android:state_selected="true"></item>
<item android:drawable="#drawable/button_bg_pressed" android:state_pressed="true"></item>
<item android:drawable="#drawable/button_bg_normal"></item>
</selector>
And use this as your View drawable:
<Button
android:id="#+id/your_button"
android:background="#drawable/selector_state_xml"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
An alternative could be using ScaleAnimation

Animation design for transitions

I need to design a component for animation rendering. Because you probably are much smarter than me I ask your opinion.How would you do the following design?
More precisely I want to have a horse which can run, stop, jump and dodge.
I can obtain all the frames needed for all these states. For example, I can draw all the frames containing the horse running(f[1] - f[n]). But what if the horse needs to dodge while running on f[k] frame (1
How can I design this type of transitions? What classes would you use? Do I need to draw transitions for every f[k]?
More details if helps: Design will be implemeneted in Android SDK.
Thank you very much!
Please try below code . hope it will work
You need to create animation-list under res/drawable
<?xml version="1.0" encoding="utf-8"?>
<animation-list xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/animationFrame"
android:oneshot="false" >
<item
android:drawable="#drawable/es0"
android:duration="100"/>
<item
android:drawable="#drawable/es1"
android:duration="100"/>
<item
android:drawable="#drawable/es2"
android:duration="100"/>
<item
android:drawable="#drawable/es3"
android:duration="100"/>
<item
android:drawable="#drawable/es4"
android:duration="100"/>
</animation-list>
Write below code in your activity
private AnimationDrawable m_frameAnimation = new AnimationDrawable();
imageView.setBackgroundResource(R.drawable.animationFrame);
m_frameAnimation = (AnimationDrawable) imageView.getBackground();
m_frameAnimation.start();

Making Android image larger when pressed, and normal when released

I have an app, that has an ImageViev, which can be clicked to perform an action. I want it to be a little bit bigger when it's pressed, and go back to normal when it's released. The problem is, I have 10 different images that appear in the ImageViev, depending on the situation. I've read a lot of threads about that, and none of the solutions seems to solve my problem. I need to:
Make an image bigger when the button is pressed, or replace it with a bigger version.
Make the image shrink when the button is released, or go back to normal version of the image.
When I change the image in the ImageView, it will still change its size when pressed.
I've tried this so far:
Creating a drawable item, that looks like this:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:state_pressed="true"
android:drawable="#drawable/b1big" />
<item
android:state_pressed="false"
android:drawable="#drawable/b1"/>
</selector>
but it won't work, because Android automatically scales the image to the size of the ImageView, so no matter if b1big is bigger than b1.
Changing the width and height of the drawable item, but it doesn't have these parameters.
Is creating 10 normal images like image1, image2... image10, then creating 10 big images like image1big... image10big and then creating 10 drawable objects like:
<item
android:state_pressed="true"
android:drawable="#drawable/image1big" />
<item
android:state_pressed="false"
android:drawable="#drawable/image1"/>
and using them as src for my ImageView? How do I prevent them from scaling then?
Update you selector's content to
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:state_pressed="true"
android:drawable="#drawable/b1big" />
<item
android:drawable="#drawable/b1"/>
</selector>

Android: How to display animation with transparent BG?

I'd like to display a animation with transparent background, on a transparent activity. How can I realize it with Android? I thought about flash, but the user has to have flash installed, right? I'd prefer vector graphics instead of gifs.
Thanks a lot in advance!
Example:
The best way to show an animation is to store them as PNGs and do something like this for an animation, put this in your drawable folder.:
<animation-list xmlns:android="http://schemas.android.com/apk/res/android" android:oneshot="false">
<item android:drawable="#drawable/ant1" android:duration="100" />
<item android:drawable="#drawable/ant2" android:duration="100" />
<item android:drawable="#drawable/ant3" android:duration="100" />
<item android:drawable="#drawable/ant2" android:duration="100" />
</animation-list>
If you want to use vector graphics, then you have to manually switch the images. You could look into svg-android, which is a great way to use simple vector images in Android.
Hey you this library for animation of background image and set theme Theme.Transparent for activity...so you can achieve your requirement This is the link might be usefull...KenBurnsView

Android layer-list spritesheet

I have created a sprite sheet (single image that contains multiple images) with 4 different icons. I would like to create a layer-list that uses different parts of the images to make a single image, for example:
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:drawable="#drawable/spritesheet"/>
<item android:drawable="#drawable/spritesheet"/>
<item android:drawable="#drawable/spritesheet"/>
<item android:drawable="#drawable/spritesheet"/>
</layer-list>
For example the sprite sheet would look something like this:
and I would like the final result to look like this:
I have tried the different options that are available here
however I can't find a solution.
Why don't you just use the parts of the picture?
#drawable/layers.xml, for example:
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:drawable="#drawable/part1"/>
<item android:drawable="#drawable/part2"/>
<item android:drawable="#drawable/part3"/>
<item android:drawable="#drawable/part4"/>
</layer-list>
And if the full picture is needed, you can use a fifth (the full) picture, or create it from the parts in a RelativeLayout thus it remains the app light-weight.

Categories

Resources