Hi all
I have to images say image1 and image2
I want to display both images on timer, only one image should be visible at a time. Both images are overlapped, meaning, image1 is over image2.
So, if I use timer, I want to be able to show one image at a time.
How do I do this.
I hope I am clear with my problem
Put your images in Drawable folder. and create an splash.xml file in drawable folder like this :
<animation-list xmlns:android="http://schemas.android.com/apk/res/android"
android:oneshot="true">
<item android:drawable="#drawable/splash_1" android:duration="200" />
<item android:drawable="#drawable/splash_2" android:duration="200" />
<item android:drawable="#drawable/splash_3" android:duration="200" />
<item android:drawable="#drawable/splash_4" android:duration="200" />
<item android:drawable="#drawable/splash_5" android:duration="200" />
</animation-list>
and in your activity class
setContentView(R.layout.splashscreen);
final ImageView splashImage = (ImageView) findViewById(R.splash.ImageView);
splashImage.setBackgroundResource(R.drawable.splash);
splashAnimation = (AnimationDrawable) splashImage.getBackground();
splashAnimation.start();
The code does not changes from first image to next.
is any thing wrong withthis code?
final ImageView splashImage = (ImageView) findViewById(R.id.ImageView01);
splashImage.setBackgroundResource(R.drawable.splash);
AnimationDrawable splashAnimation = (AnimationDrawable) splashImage.getBackground();
splashAnimation.start();
Related
I need help in make the background of my app as gallery of photos... is that possible? and how to do that?
You can use a GridView to show images in column and row fashion. For more information you can take a look at this article for implementing gridview.
You can do this by assigning an id to your parent layout and then in java you can change the background image after a certain action is performed.
You can use Asyymmetric Gridview to achive attractive view of gallery
you can use this library
Yes You can I did it before by creating an animation that contain the images then I set this animation as backgroud
// Type casting the Image View
ImageView view = (ImageView) findViewById(R.id.imageView1);
// Setting animation_list.xml as the background of the image view
view.setBackgroundResource(R.anim.animation);
// Type casting the Animation drawable
AnimationDrawable frameAnimation = (AnimationDrawable) view.getBackground();
frameAnimation.start();
example animation 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/image_1" android:duration="3000" />
<item android:drawable="#drawable/image_2" android:duration="3000" />
<item android:drawable="#drawable/image_3" android:duration="3000" />
</animation-list>
Is there any way to make a ProgressBar like this.
Or can it be achieved by customizing RatingBar as an indicator?
If so, how would I be able to attach the lines in between the circles?
You can achieve this by using different images which represents different stages of your process
keep an imageview with visibility gone and make it visible when you want to display the same
in your drawable folder keep an xml like the following progressanimation.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/progressone" android:duration ="400" />
<item android:drawable="#drawable/progresstwo" android:duration="400" />
<item android:drawable="#drawable/progressthree" android:duration="400" />
<item android:drawable="#drawable/progressfour" android:duration="400" />
</animation-list>
and use this as background of your ImageView like follows
iv.setVisibility(View.VISIBLE);
iv.setBackgroundResource(R.drawable.progressanimation);
final AnimationDrawable mailAnimation = (AnimationDrawable) iv
.getBackground();
iv.post(new Runnable() {
public void run() {
if (mailAnimation != null)
mailAnimation.start();
System.out.println("anim wrkingggg");
}
});
here iv is your imageview.This code will change the background automatically.You can make the runnable run with your own timelimit.
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!
I want to create an android game. Everytime someone touches the display the player should go up, and if he releases the player should fall.
With the help of many tutorials I made it work but now I want to animate it and I'm stuck. That means the image of the player should be changed every half a second. Additionally an animated rotation should be created when the player goes up.
However (after hours of googling) I couldnt find any helpful answer to my problem. The Android Developers site talks about creating an ImageView and a XML file. But thats where I'm stuck: I dont have an ImageView, my player (for which I used a PNG file) is simply created by the onDraw() method:
public void onDraw(Canvas canvas) {
for (Sprite s : sprites) {
canvas.drawBitmap(s.getGraphic(), s.getLocation().x,
s.getLocation().y, null);
}
}
Now I wanted to ask how I should do the animation and the animated rotation. Should I start off with an ImageView or can I somehow "convert" the onDraw method to an ImageView? Or is there another way to do the animation and animated rotation without an ImageView?
Secondly, if I had to create the ImageView I don't understand how I can make the player "dynamic", i.e.: changing the position when someone touches the display.
Thanks in advance :)
EDIT:
Ok, I created my animation.xml file in the drawable folder:
<animation-list xmlns:android="http://schemas.android.com/apk/res/android" android:oneshot="false" android:id="#+id/splashAnimation">
<item android:drawable="#drawable/ship" android:duration="200" />
<item android:drawable="#drawable/ship_2" android:duration="200" />
</animation-list>
and in my main file I added:
ImageView img = (ImageView) findViewById(R.id.splashAnimation);
img.setBackgroundResource(R.drawable.animation);
ship_anim= (AnimationDrawable) img.getBackground();
ship_anim.start();
However, now I get the error message: NullPointerException
Where is the Problem?
if you have drawables that describe animation, you can always create xml in your drawable folder like this than add this as imageView to the layout
<?xml version="1.0" encoding="utf-8"?>
<animation-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:drawable="#drawable/img1" android:duration="100" />
<item android:drawable="#drawable/img2" android:duration="100" />
<item android:drawable="#drawable/img3" android:duration="100" />
<item android:drawable="#drawable/mimg4" android:duration="100" />
<item android:drawable="#drawable/img5" android:duration="100" />
</animation-list>
The code for it would look like this:
myAnimation = (AnimationDrawable) findViewById(R.id.animation);
Add just event handler than
if (!isPlaying)
{
playDrawableAnimation();
isPlaying = true;
} else
{
faceAnimation.stop();
isPlaying = false;
}
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