Hi All,
The frame animation works fine according to this thread, thanks.
My question is: how to set the duration of the frame by code (not by
XML). The following is my code to implement the frame animation by
code:
--
        button2.setOnClickListener(new OnClickListener() {
                        @Override
                        public void onClick(View v) {
                                img = (ImageView) 
findViewById(R.id.spinning_wheel_image);

                                frameAnimation = new AnimationDrawable();

                                DrawableContainerState containerState = 
(DrawableContainerState)
frameAnimation.getConstantState();

                                long duration = 10000L;
                                long now = SystemClock.uptimeMillis();
                                long i = 0L;

                                Drawable d = 
getResources().getDrawable(R.drawable.wheel0);
                                containerState.addChild(d);
                                frameAnimation.scheduleDrawable(d, 
frameAnimation, now
+i*duration);
                                i++;

                                d = 
getResources().getDrawable(R.drawable.wheel1);
                                containerState.addChild(d);
                                frameAnimation.scheduleDrawable(d, 
frameAnimation, now
+i*duration);
                                i++;

                                d = 
getResources().getDrawable(R.drawable.wheel2);
                                containerState.addChild(d);
                                frameAnimation.scheduleDrawable(d, 
frameAnimation, now
+i*duration);
                                i++;

                                d = 
getResources().getDrawable(R.drawable.wheel3);
                                containerState.addChild(d);
                                frameAnimation.scheduleDrawable(d, 
frameAnimation, now
+i*duration);
                                i++;

                                d = 
getResources().getDrawable(R.drawable.wheel4);
                                containerState.addChild(d);
                                frameAnimation.scheduleDrawable(d, 
frameAnimation, now
+i*duration);
                                i++;

                                d = 
getResources().getDrawable(R.drawable.wheel5);
                                containerState.addChild(d);
                                frameAnimation.scheduleDrawable(d, 
frameAnimation, now
+i*duration);
                                i++;

                                img.setImageDrawable(frameAnimation);

                                frameAnimation.start();
                        }
--
The frame animation will work, but unable to set the duration,
AnimationDrawable.scheduleDrawable() doesn't work.


On Mar 23, 12:34 pm, "Dan U." <[EMAIL PROTECTED]> wrote:
> I tested the code and I did get it to work, but I don't think it's
> working quite the way you'd expect. It seems if you try to start the
> animation in one of the activity methods such as onCreate, onStart,
> onResume, it will not start (only shows the first image). The Activity
> docs say onResume is a good place to start animations, but the
> animation would not start for me there.
>
> What I did to make it work was added a button and set a
> OnClickListener that started the animation. Obviously that isn't the
> greatest if you are expecting your animation to start when the
> Activity is displayed. If you didn't care about an ugly hack, you
> could probably start a thread that would sleep for awhile and then
> start the animation.
>
> On Mar 18, 9:49 pm, Parth <[EMAIL PROTECTED]> wrote:
>
> > Hi,
> > its nt wrking. Its showing only first image.
> > Plz let me know if anyones wrking....
>
> > On Mar 18, 11:56 am, "Romain Guy" <[EMAIL PROTECTED]> wrote:
>
> > > Oh sorry, there's a typo in the example:
>
> > > oandroid:neshot="false"
>
> > > should be:
>
> > > android:oneshot="false"
>
> > > On 3/17/08, Parth <[EMAIL PROTECTED]> wrote:
>
> > > >  Hey, its nt wrking. Showing an error in spin_animation.xml file.
>
> > > >  Error: Error parseing XML: Unbound Prefix.
>
> > > >  <?xml version="1.0" encoding="utf-8"?>
> > > >    <animation-list android:id="selected" android:neshot="false">
> > > >     <item android:drawable="@drawable/a" android:duration="50" />
> > > >     <item android:drawable="@drawable/b" android:duration="50" />
> > > >     <item android:drawable="@drawable/c" android:duration="50" />
> > > >     <item android:drawable="@drawable/d" android:duration="50" />
> > > >     <item android:drawable="@drawable/e" android:duration="50" />
> > > >   </animation-list>
>
> > > >  On Mar 17, 10:50 pm, "Romain Guy" <[EMAIL PROTECTED]> wrote:
> > > >  > It certainly works. Here is the updated documentation:
>
> > > >  > An object used to define frame-by-frame animations that can be used 
> > > > as
> > > >  > a View object's background.
>
> > > >  > Each frame in a frame-by-frameanimationis a drawable resource. The
> > > >  > simplest way to create a frame-by-frameanimationis to define 
> > > > theanimationin an XML file in the drawable/ folder, set it as the
> > > >  > background to a View object, then call AnimationDrawable.run() to
> > > >  > start theanimation, as shown here. More details about the format of
> > > >  > theanimationXML file are given in Frame by FrameAnimation.
> > > >  > spin_animation.xml file in res/drawable/ folder:
>
> > > >  > <!--Animationframes are wheel0.png -- wheel5.png files inside the
> > > >  >  res/drawable/ folder -->
> > > >  >  <animation-list android:id="selected" oandroid:neshot="false">
> > > >  >     <item android:drawable="@drawable/wheel0" android:duration="50" 
> > > > />
> > > >  >     <item android:drawable="@drawable/wheel1" android:duration="50" 
> > > > />
> > > >  >     <item android:drawable="@drawable/wheel2" android:duration="50" 
> > > > />
> > > >  >     <item android:drawable="@drawable/wheel3" android:duration="50" 
> > > > />
> > > >  >     <item android:drawable="@drawable/wheel4" android:duration="50" 
> > > > />
> > > >  >     <item android:drawable="@drawable/wheel5" android:duration="50" 
> > > > />
> > > >  >  </animation-list>
>
> > > >  > Here is the Java code to load and play thisanimation.
>
> > > >  > // Load the ImageView that will host theanimationand
> > > >  >  // set its background to our AnimationDrawable XML resource.
> > > >  >  ImageView img = (ImageView)findViewById(R.id.spinning_wheel_image);
> > > >  >  img.setBackground(R.drawable.spin_animation);
>
> > > >  >  // Get the background, which has been compiled to an 
> > > > AnimationDrawable object.
> > > >  >  AnimationDrawable frameAnimation = (AnimationDrawable) 
> > > > img.getBackground();
>
> > > >  >  // Start theanimation(looped playback by default).
> > > >  >  frameAnimation.start()
>
> > > >  > On Mon, Mar 17, 2008 at 10:38 AM, sasperilla <[EMAIL PROTECTED]> 
> > > > wrote:
>
> > > >  > >  Romain,
>
> > > >  > >  Thanks for the response.  Good to know that the docs are 
> > > > outdated, but
> > > >  > >  does it actually work?  Correcting documentation will be good, 
> > > > but if
> > > >  > >  it works then someone from Google could just give us the correct
> > > >  > >  version here on the newsgroup so I could get my code working now
> > > >  > >  before the release.
>
> > > >  > >  Charlie
>
> > > >  > >  On Mar 17, 12:13 pm, "Romain Guy" <[EMAIL PROTECTED]> wrote:
> > > >  > >  > Hi,
>
> > > >  > >  > The docs are outdated. The next version of the SDK will provide 
> > > > a
> > > >  > >  > correct version of the documentation.
>
> > > >  > >  > On Mon, Mar 17, 2008 at 5:54 AM, sasperilla <[EMAIL PROTECTED]> 
> > > > wrote:
>
> > > >  > >  > >  I know there were some issues with frame by frame animations 
> > > > in M3,
> > > >  > >  > >  but are they working in M5.  The docs give an example that 
> > > > no one has
> > > >  > >  > >  been able to get working.  And this thread implies that the 
> > > > docs are
> > > >  > >  > >  actually just plain wrong.
>
> > > >  > >  > >  
> > > > http://groups.google.com/group/android-developers/browse_thread/threa...
>
> > > >  > >  > >  But, I haven't seen google say anything regarding if these 
> > > > is working
> > > >  > >  > >  or not.
>
> > > >  > >  > >  Charlie
>
> > > >  > >  > --
> > > >  > >  > Romain Guywww.curious-creature.org
>
> > > >  > --
> > > >  > Romain Guywww.curious-creature.org-Hidequotedtext -
>
> > > >  > - Show quoted text -
>
> > > --
> > > Romain Guywww.curious-creature.org-Hidequoted text -
>
> > > - Show quoted text -
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[EMAIL PROTECTED]
Announcing the new M5 SDK!
http://android-developers.blogspot.com/2008/02/android-sdk-m5-rc14-now-available.html
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to