我怎么补间动画添加到我的自定义视图? [英] How do I add a tween animation to my custom view?
问题描述
这是我的第一个Android项目,如此忍受我。我创建了通过重写OnDraw中绘制我的游戏棋盘和棋子的自定义视图(游戏键盘扩展视图)。这一切工作正常。不过,我想在比赛的末尾添加补间动画你赢了的图形。但是,我无法弄清楚如何将ImageView的添加到我的游戏键盘视图。
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.
我看了,我可以用一个XML文件,并添加我的自定义视图,但没有奏效。这里是我的XML code:
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>
我也认为标签试了一下没有视图类=。我也试了一下,而不在视图标签中的.GameBoard,并在其指定机器人:ID =标签。 (所有这些尝试从谷歌搜索来的。)
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.)
如果我能得到它的工作,我想我可以用我的位图添加的ImageView为背景,将其放置在正确的位置,和动画吧。我做了类似的事情对我的标题画面,它工作正常,但它使用的XML本身,没有一个自定义视图。 (事后看来,我不知道我是否应该使用XML,而不是为游戏板自定义视图,但那是另一回事)。
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 thing 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.)
谁能帮助吗?
推荐答案
这似乎回答你的问题。
This seems to answer your question.
的http://sankarganesh-info-exchange.blogspot.com/2011/04/performing-animation-in-android.html
只需调用target.startAnimation()方法时,你的用户赢得/输/凡是你的游戏
just call the target.startAnimation() method when your user wins / loses / whatevers your game
这篇关于我怎么补间动画添加到我的自定义视图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!