开发者

How do I add a tween animation to my custom view?

This is my first Android project, so bear with me. I created a custom view ("GameBoard" extends View) for drawing my game board and pieces by overriding the OnDraw. It all works fine. However, I'd like to add a tween-animated "You win" graphic at the end of the game. However, I can't figure out how to add an ImageView to my GameBoard view.

I read that I could use an XML file and add my custom view to it, but it didn't work. Here's my XML code:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
  android:background="#001133" >

  <view Class = "com.myname.firstgame.GameBoard"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
  </view>

</RelativeLayout>

I also tried it without the "view Class =" in the view tag. I also tried it without the ".GameBoard" in the view tag and specifying it in the "android:id=" tag. (All these attempts came from Google searches.)

If I can get it to work, I figure I can add an ImageView with my bitmap as the background, place it in the right spot, and animate it. I do a similar thin开发者_如何学编程g for my title screen and it works fine, but it uses an XML natively, without a custom view. (In hindsight, I'm wondering if I should have used XML rather than a custom view for the game board, but that's another matter.)

Can anyone help, please?


This seems to answer your question.

http://sankarganesh-info-exchange.blogspot.com/2011/04/performing-animation-in-android.html

just call the target.startAnimation() method when your user wins / loses / whatevers your game

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜