开发者

How to position a FrameAnimation in android?

I have a image loaded as a background and when the screen is touched I want to animate that portion of the screen with a frameanimation. My frameanimation consists of 9 different png files which are made from just the portion of the screen I want animated. I ca开发者_运维技巧n get it working when I use entire backgrounds as the frames for the animations, but when I use setbounds() to tell the frameanimation where to draw, I end up with the frameanimation being scaled up to fill the entire screen, which also erase my background. How can I get the frameanimation to stay it's original size and locate it at the same time? I can post code later if this isn't clear, i'm not at the comp right now

public boolean onTouchEvent (MotionEvent event)
{
   switch (event.getAction())
   {
      case MotionEvent.ACTION_DOWN:
         this.setBackgroundResource (R.drawable.nova);
         Object bg = this.getBackground
         touchAni.setBounds (152, 156, 152+140, 156+140);

         touchAni = (AnimationDrawable) bg;

         if (!touchAni.isRunning())
            touchAni.start ();
         else
         {
            touchAni.stop();
            touchAni.start();
         }
   }
}


The way I have resolved a similar problem is that I added another image component to my layout xml on top of the component I want to animate. Normally that image component is android:visibility="gone" but when I want to run the frame animation I set it visible and start the animation.

This way you can place the animation component wherever you want in your layout.


Well, after much puttering around, I finally found the BounceActivity code here: http://rsequence.com/android_blog/node/107. Seems really complicated for such a simple task but gets me what I want.

Of note, if anyone else finds it useful, the Handler() codes needs to have a switch in it so it's not spinning off cpu cycles to BounceView.draw() when nothing is happening on the screen.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜