Animation-list not working - shows only the first element - android

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.

Related

setting gif image toProgressBar

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.

gif with Listview in Android

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.

Can I make the background of the android application as group of images?

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>

how to access a particular item in the animation list

I have a animation list contains the following items
<?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/b1"
android:duration="500"/>
<item
android:drawable="#drawable/delay"
android:duration="1000"/>
<item
android:drawable="#drawable/b1"
android:duration="500"/>
<item
android:drawable="#drawable/delay"
android:duration="1000"/>
<item
android:drawable="#drawable/b2"
android:duration="500"/>
Now, when the animation is running or has started by the following
code,
img1 = (ImageView)findViewById(R.id.stimulichangeid);
img1.setBackgroundResource(R.drawable.erp_simple_presentationlist1);
AnimationDrawable splashanimation = (AnimationDrawable)img1.getBackground();
splashanimation.start();
I want to click some button when in animation list "b2" drawable
appears on the imageview.But in a running animation, how to access a
particular item(in my case b2). When b2 comes i want to press a button
and do something. i was thinking to assign id's to every item. if yes,
then how to access that particular item with its id when the
animation is running. please suggest some way to solve this problem.
thanks in advance
AnimationDrawable isn't kind of layout so you can't catch any child view with order. It just replaces a drawable with a new one, so you need a kind of listener returns the order of new drawable. And native implementation doesn't have these kind of listener.
There is some custom AnimationDrawables and you can modify one of these for your need.

Translation animation of large image from top to bottom Android

I'm trying to develop a splash screen with a large image scrolling (Animating) from top to bottom.
I dont think using ScrollView would be good since I dont want the user to scroll the image.
This is what I would like to achieve:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="200"
android:fromYDelta="-100%p"
android:toYDelta="100%p"
>
</translate>
</set>
create this animation as slidedown.xml in an anim folder in the project and use the code below in the java file that has the view.You may change the values of "android:fromYdelta" according to your need.
myImageView.startAnimation(slidedown);
For example if your imageview is 250 px use :
ObjectAnimator.ofFloat(myImageView, "translationY", 250);
And in xml set on your imageview :
android:translationY="-250"

Categories

Resources