android create custom progressbar like that - android

i want to create a progressbar in android like that image
i try to use
<animated-rotate xmlns:android="http://schemas.android.com/apk/res/android"
android:drawable="#drawable/loadingicon"
android:pivotX="50%"
android:pivotY="50%" />
but i think it not meet in my requirement

Here is a good example to customize progressbar: http://developer.android.com/reference/android/graphics/drawable/AnimationDrawable.html
U must draw all state of you future progress bar (img1.png, img2.png, img3.png, img4.png). put image to /res/drawable.
pb_animation.xml:
<animation-list android:id="#+id/myprogressrbar" android:oneshot="false">
<item android:drawable="#drawable/img1" android:duration="50" />
<item android:drawable="#drawable/img2" android:duration="50" />
<item android:drawable="#drawable/img3" android:duration="50" />
<item android:drawable="#drawable/img4" android:duration="50" />
</animation-list>
And then, in yor code:
ImageView img = (ImageView)findViewById(R.id.spinning_wheel_image);
img.setBackgroundResource(R.drawable.pb_animation);
AnimationDrawable frameAnimation = (AnimationDrawable) img.getBackground();
frameAnimation.start();

you could use an AnimationDrawable in combination with an ImageView and add a drawable for every state of your loading indicator, but a better way to this, is creating a new Style for a ProgressBar view (by extending de platform default style) and use your AnimationDrawable as loading indicator.
The Android styles are open source, so you can easily find them and extend them for your needs.
Good luck!

Related

How to bring animated effects in background in Android app?

I am trying to add an animation ( not sure if that would be an appropriate word ) of beach waves when my app loads with its first screen.I am developing a holiday app and have already set an image (a static image of sand ) as the background.I am expecting to have the sand image as background and have an effect of the waves hitting the shore.How should go about achieving this? I want the waves in this pic in motion--> http://www.wallpapervortex.com/wallpaper-23493_beach_sand_sand_beach.html#.U9Rr2fldW8A
Have each frame as a seperate image in the drawable folder. After that, use an xml to define the frames(eg, ANIMATED.xml)
<animation-list android:id="#+id/selected" android:oneshot="false">
<item android:drawable="#drawable/0" android:duration="50" />
<item android:drawable="#drawable/1" android:duration="50" />
<item android:drawable="#drawable/2" android:duration="50" />
<item android:drawable="#drawable/3" android:duration="50" />
<item android:drawable="#drawable/4" android:duration="50" />
<item android:drawable="#drawable/5" android:duration="50" />
</animation-list>
And to make it animate, use this:
// Load the ImageView that will host the animation and
// set its background to our AnimationDrawable XML resource.
ImageView img = (ImageView)findViewById(R.id.moving_image);
img.setBackgroundResource(R.drawable.ANIMATED.xml);
// Get the background, which has been compiled to an AnimationDrawable object.
AnimationDrawable frameAnimation = (AnimationDrawable) img.getBackground();
// Start the animation (looped playback by default).
frameAnimation.start();

Background animation image on ProgressBar on Android?

What is the appropriate action to take when you need to change the background image of a ProgressBar? I mean should use a .gif image like : http://2.bp.blogspot.com/-O7nsXfmgwSc/T6PQ0PVr6-I/AAAAAAAAAQI/-eXkEXj24-s/s1600/02.gif and if so will the foreground color of the bar fill the image file during the proccess ? Is there a way of creating an animation for the background of the bar ? What i am aiming for is to show the animation for as long the process does not cover the full bar.
you need to get all this gif frame image as individual and then set into the animation-list in xml file.
Here is your anim_progress.xml file code
<?xml version="1.0" encoding="utf-8"?>
<animation-list xmlns:android="http://schemas.android.com/apk/res/android"
android:oneshot="false">
<item android:drawable="#drawable/i1" android:duration="500" />
<item android:drawable="#drawable/i2" android:duration="500" />
<item android:drawable="#drawable/i3" android:duration="500" />
<item android:drawable="#drawable/i4" android:duration="500" />
<item android:drawable="#drawable/i5" android:duration="500" />
<item android:drawable="#drawable/i6" android:duration="500" />
<item android:drawable="#drawable/i7" android:duration="500" />
<item android:drawable="#drawable/i8" android:duration="500" />
</animation-list>
set the duration for change as smooth effect for giving animated image like gif
Here is the code for using this file
ImageView iv = new ImageView(this);
iv.setBackgroundResource(R.drawable.anim_progress);
final AnimationDrawable mailAnimation = (AnimationDrawable) iv.getBackground();
iv.post(new Runnable() {
public void run() {
if ( mailAnimation != null ) mailAnimation.start();
}
});
setContentView(iv);
you can get all frames from gif file from this site.
http://gif-explode.com/
for example
http://2.bp.blogspot.com/-O7nsXfmgwSc/T6PQ0PVr6-I/AAAAAAAAAQI/-eXkEXj24-s/s1600/02.gif
this link just pass it and you will get all the frame images

Designing animation for android application

What is the best way to design and embed an animation into an android app.
(I'm not talking about transitions and activities in/out animations.)
I can think of 2 ways of doing it:
designing the animation with flash or something similar, export png-sequence with transparent bgs and creating an animation from the images in an xml file (How do I write this kind of xml?)
creating a grid of images with all the frames of the animation that I've created
and save it into one image. than using something like background-position in css in order to move the visible area of the image on each frame enter (By Java code, or by xml)
which of this is better/most common? and how do I implement the solution (if there is a better solution - that would be great).
and what programs do you usually use for this kind of task
(the goal is to achieve something that works like the frog in cut the rope or the birds in angry birds for example)
thanks!
I used simple animation in one project... It's on your first point... A sequence of *.png files in /res/drawable, and *.xml like:
<?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/s250" android:duration="200" />
<item android:drawable="#drawable/s251" android:duration="200" />
<item android:drawable="#drawable/s252" android:duration="200" />
<item android:drawable="#drawable/s253" android:duration="200" />
<item android:drawable="#drawable/s254" android:duration="200" />
<item android:drawable="#drawable/s255" android:duration="200" />
<item android:drawable="#drawable/s256" android:duration="200" />
<item android:drawable="#drawable/s257" android:duration="200" />
<item android:drawable="#drawable/s258" android:duration="200" />
</animation-list>
... and source...
final ImageView pygalo = (ImageView) findViewById(R.id.imageanimation);
pygalo.setBackgroundResource(R.anim.animation);
final AnimationDrawable pygaloanimation = (AnimationDrawable) pygalo.getBackground();
pygalo.setOnClickListener(new OnClickListener()
{
#Override
public void onClick(View vp) {
pygaloanimation.stop();
pygaloanimation.start();
}
});
It is very easy to do...

Android transition animation

I want an animated gif, since this isn't possible in Android I am using individual frames in a transition.
except it seems like the transition class only will show two frames ever! I saw other animation methods but they didn't seem to apply to what I was doing, or seemed old and convulated like for an older infant android build
<transition xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="#drawable/activateanima"></item>
<item android:drawable="#drawable/activateanimb"></item>
<item android:drawable="#drawable/activateanimc"></item>
<item android:drawable="#drawable/activateanimc"></item>
<item android:drawable="#drawable/activateanimd"></item>
<item android:drawable="#drawable/activateanime"></item>
<item android:drawable="#drawable/activateanimf"></item>
<item android:drawable="#drawable/activateanimg"></item>
</transition>
How do I animate an image to behave like an animated gif, in place. no rotations or translations here. Using android 2.1+
Are you after a Frame animation? See: here. This will play a standing still animation.
Example from above site:
XML file saved at res/anim/rocket.xml:
<?xml version="1.0" encoding="utf-8"?>
<animation-list xmlns:android="http://schemas.android.com/apk/res/android"
android:oneshot="false">
<item android:drawable="#drawable/rocket_thrust1" android:duration="200" />
<item android:drawable="#drawable/rocket_thrust2" android:duration="200" />
<item android:drawable="#drawable/rocket_thrust3" android:duration="200" />
</animation-list>
To use:
ImageView rocketImage = (ImageView) findViewById(R.id.rocket_image);
rocketImage.setBackgroundResource(R.drawable.rocket_thrust);
rocketAnimation = (AnimationDrawable) rocketImage.getBackground();
rocketAnimation.start();
Just use a view flipper to flip between the images. Just define your in and out animations to be 0seconds long and they should be instantianous. (but use alpha to be sure). View flipper has the benefit of also auto animating and auto starting

Android: creating an animation on touch

I wanted to create a frame by frame animation when the user touches the screen. The images I've decided to use should appear, animate and disappear at the touched coordinates.
<animation-list xmlns:android=
"http://schemas.android.com/apk/res/android"
android:oneshot="true">
<item android:drawable="#drawable/animation1" android:duration="50" />
<item android:drawable="#drawable/animation2" android:duration="50" />
<item android:drawable="#drawable/animation3" android:duration="50" />
<item android:drawable="#drawable/animation4" android:duration="50" />
</animation-list>
I attempted to do this via drawable.animationdrawable but it seems like I needed to have the image on screen in the main.xml before I can do this. Is there a way I can do it without having this code in the main.xml?
<ImageView
android:id="#+id/animation1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
you can easily set source for your ImageView using java code. Get reference to imageview in xmllayout. for eg. imageview is image
then do image.setResource(a drawable to be passed here).
Create a view + add visibilty_GONE + add set_anim property, as you have defined your animation file.
Use some onDown(MotionEvent e).
Inside this onDown, set your view_visibilty_VISIBLE.

Categories

Resources