I have used GIF image to the progress bar using library its working fine but problem is that it doesn't repeat the animation
loading_dialog = new ProgressDialog(LeadProfile.this, style.MyInnerProgressDialogTheme);
loading_dialog.setCancelable(false);
loading_dialog.setIndeterminateDrawable(GifDrawable.createFromResource(getResources(), drawable.home_loder));
loading_dialog.setProgressStyle(android.R.style.Widget_ProgressBar_Small);
loading_dialog.show();
can anybody help me .. i have even used the custom window view and custom dialog it is still not working that is not repeating the animation though the GIF image have that repetition
You can use Animation Drawable instead.
You will need sequence of images for that(you can create it from gif itself
In your Activity or Dialog
// ImageView that will act as loader. it can be added in `Activity` or `Dialog`
ImageView loading_dialog = (ImageView);
findViewById(R.id.loading_dialog);
loading_dialog.setBackgroundResource(R.drawable.preloader);
AnimationDrawable animationDrawable = (AnimationDrawable) loading_dialog.getBackground();
animationDrawable = (AnimationDrawable) preLoader.getBackground();
// to start animation
animationDrawable.start();
// to stop animation
animationDrawable.stop();
And in drawable folder create preloader.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/preloader1"
android:duration="45"/>
<item
android:drawable="#drawable/preloader2"
android:duration="45"/>
<item
android:drawable="#drawable/preloader3"
android:duration="45"/>
<item
android:drawable="#drawable/preloader4"
android:duration="45"/>
<item
android:drawable="#drawable/preloader5"
android:duration="45"/>
if you want to run this only once change android:oneshot:"true"
and you can have as many as items you images. and you can change duration for one image too.
Related
I want to change the background of my android app automatically after few milliseconds. So first I created a drawable resource file "colorchange.xml" with the content
<animation-list android:oneshot="false" xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="#color/color1" android:duration="1" />
<item android:drawable="#color/color2" android:duration="2" />
<item android:drawable="#color/color3" android:duration="3" />
<item android:drawable="#color/color4" android:duration="4" />
<item android:drawable="#color/color5" android:duration="5" />
And I used this as background in my main xml file
Now only color1 is set as background. Animation of colors is not showing as background.
What is the problem in this and how can I achieve my goal ?
you can define your colors in colors.xml like this:
<color name="yourcolor">#0FFF</color>
then you can use it like this:
<item android:drawable=#colors/yourcolor android:duration="5" />
Check when are you starting the animation. According documentation you should not use animation on onCreate() method.
Note: Do not call this in the onCreate(Bundle) method of your
activity, because the AnimationDrawable is not yet fully attached to
the window. If you want to play the animation immediately without
requiring interaction, then you might want to call it from the
onWindowFocusChanged(boolean) method in your activity, which will get
called when Android brings your window into focus.
EDIT - An example of how to use Animation:
// Load the View that will host the animation and
// set its background to our AnimationDrawable XML resource.
LinearLayout linearLayout = (LinearLayout) layout.findViewById(R.id.example_view);
linearLayout.setBackgroundResource(R.drawable.colorchange);
// Get the background, which has been compiled to an AnimationDrawable object.
AnimationDrawable frameAnimation = (AnimationDrawable) linearLayout.getBackground();
// Start the animation (looped playback by default).
frameAnimation.start();
You shold define your colors in value/colors.xml file and use it like android:drawable="#color/MyGreen"
I am new to Android. I Have Listview in My Activity and it's working Fine. But suddenly in mind one thought is going on. Is there any way to put gif animation in background of my Listview and display data to on gif Image. Let's say that In Our Listview we Have set background color as follow.
android:background="#color/Mycolor
so it can change the whole Listview color But I want to
display gif Animation Like small Image of Birds are flying in
Background
. If it is possible then give suggestion.
Any Help will be Appreciated.
I think this is the way you can set,first you need to divide gif animation in indvidual frame,then you need to create one xml for background and use animation-list and add all the frames of gif image and set that xml as background
<animation-list xmlns:android="http://schemas.android.com/apk/res/android"
android:oneshot="false" >
<item
android:drawable="#drawable/frame1"
android:duration="1000"/>
<item
android:drawable="#drawable/frame2"
android:duration="1000"/>
<item
android:drawable="#drawable/frame3"
android:duration="1000"/>
....
</animation-list>
use an Imageview in row background and play gif on it using this component.
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>
I am displaying number of icon on map, now i want those icon should blink, please guide me how to that.
can we use two image for light and dim, but main problem is that how to change that overlay image or how to put animation on that image to blink.
Thanks in advance.
if you are using ImageView for icon then put below xml in drawable and use as a Imageview src.
<animation-list android:id="#+id/my_animation" android:oneshot="false"
xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="#drawable/image1" android:duration="150" />
<item android:drawable="#drawable/image2" android:duration="150" />
</animation-list>
and use below code to set animation
ImageView img = (ImageView)findViewById(R.id.imageView);
AnimationDrawable frameAnimation = (AnimationDrawable)img.getDrawable();
frameAnimation.setCallback(img);
frameAnimation.setVisible(true, true);
frameAnimation.start();
You have to make a custom view and use it as a Map Overlay.
Tell Its OnDraw() to invallidate whole view after 500ms and everytime drawing again use alternative image.
This link might be helpful to you:
http://blog.pocketjourney.com/2008/03/19/tutorial-2-mapview-google-map-hit-testing-for-display-of-popup-windows/
Problem:
Shows only the first element in the animation-list.
Animation list drawable file in res/drawable:
<?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/k2si"
android:duration="1000"/>
<item
android:drawable="#drawable/android"
android:duration="1000"/>
</animation-list>
Starting the animation:
ImageView image = (ImageView) findViewById(R.id.imageView1);
image.setBackgroundResource(R.drawable.screensaver_image);
((AnimationDrawable) image.getBackground()).start();
Documentation (scroll to Frame animation)
Please see the similar question here
Starting frame by frame animation
you will get an idea about frame by frame animation.
If you didn't understood check the link below, good tutorial for frame by frame animation using XML file.
frame by frame xml animation with google android
You can achieve same thing from layout xml itself,
just mentioned android:src="#drawable/rode_anim" which is nothing but your custom animation-list drawable.