Android 中制作动画的推荐方式

发布于 2024-10-11 08:33:02 字数 308 浏览 1 评论 0原文

我在网上搜索了有关在 Android 中为角色设置动画的更多信息,但并没有完全理解它。我在这里问也许你可以给我一些关于如何以最好的方式做到这一点的建议或提示。

场景

想象 5 个绘制的角色(假设有 5 个人头)。我需要让它们动起来。我所说的动画是指让眼睛眨动、微笑、大笑等。现在我正在努力为每个动画制作位图资源。例如,对于眨眼动画,基本上我有 3 个图像,一张睁着眼睛,一张半闭着眼睛,一张闭着眼睛。我需要为角色设置动画才能使用所有这 3 个图像。

这就是我需要的所有动画,没有比这更奇特的了。有什么建议从哪里开始吗?

I've searched around the web to learn more about animating a character in Android but didn't fully understood it. I ask here maybe you could give me some advices or hints on how to make it in the best possible way.

Scenario

Imagine 5 drawn characters (let's say 5 human heads). I need to animate them. By animation I mean make eyes blink, smile, laugh etc. Right now I am working on making bitmap resources on each animation. For example for the blink animation, basically I have 3 images, one with eyes open, one with eyes half closed, one with eyes closed. I need to animate the character to use all these 3 images.

This is all the animation I need, nothing more fancier. Any suggestions from where to start ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

北座城市 2024-10-18 08:33:02
AnimationDrawable frameAnimation;
frameAnimation = (AnimationDrawable) addselection.getBackground();

@Override
public void onWindowFocusChanged(boolean hasFocus) {
    frameAnimation.start();
    super.onWindowFocusChanged(hasFocus);
}

使用这种类型的 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/add_selection0001" android:duration="50" />
    <item android:drawable="@drawable/add_selection0002" android:duration="50" />
    <item android:drawable="@drawable/add_selection0003" android:duration="50" />
    <item android:drawable="@drawable/add_selection0004" android:duration="50" />
    <item android:drawable="@drawable/add_selection0005" android:duration="50" />
    <item android:drawable="@drawable/add_selection0006" android:duration="50" />
    <item android:drawable="@drawable/add_selection0007" android:duration="50" />
    <item android:drawable="@drawable/add_selection0008" android:duration="50" />
    <item android:drawable="@drawable/add_selection0009" android:duration="50" />
    <item android:drawable="@drawable/add_selection0010" android:duration="50" />
    <item android:drawable="@drawable/add_selection0011" android:duration="50" />
    <item android:drawable="@drawable/add_selection0012" android:duration="50" />
    <item android:drawable="@drawable/add_selection0013" android:duration="50" />
    <item android:drawable="@drawable/add_selection0014" android:duration="50" />
    <item android:drawable="@drawable/add_selection0015" android:duration="50" />
    <item android:drawable="@drawable/add_selection0016" android:duration="50" />
    <item android:drawable="@drawable/add_selection0017" android:duration="50" />
    <item android:drawable="@drawable/add_selection0018" android:duration="50" />
    <item android:drawable="@drawable/add_selection0019" android:duration="50" />
    <item android:drawable="@drawable/add_selection0020" android:duration="50" />
 </animation-list>

,为您的序列动画设置不同的图像。将此可绘制对象设置为 imageview 中的背景

AnimationDrawable frameAnimation;
frameAnimation = (AnimationDrawable) addselection.getBackground();

@Override
public void onWindowFocusChanged(boolean hasFocus) {
    frameAnimation.start();
    super.onWindowFocusChanged(hasFocus);
}

add drawable using this type of 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/add_selection0001" android:duration="50" />
    <item android:drawable="@drawable/add_selection0002" android:duration="50" />
    <item android:drawable="@drawable/add_selection0003" android:duration="50" />
    <item android:drawable="@drawable/add_selection0004" android:duration="50" />
    <item android:drawable="@drawable/add_selection0005" android:duration="50" />
    <item android:drawable="@drawable/add_selection0006" android:duration="50" />
    <item android:drawable="@drawable/add_selection0007" android:duration="50" />
    <item android:drawable="@drawable/add_selection0008" android:duration="50" />
    <item android:drawable="@drawable/add_selection0009" android:duration="50" />
    <item android:drawable="@drawable/add_selection0010" android:duration="50" />
    <item android:drawable="@drawable/add_selection0011" android:duration="50" />
    <item android:drawable="@drawable/add_selection0012" android:duration="50" />
    <item android:drawable="@drawable/add_selection0013" android:duration="50" />
    <item android:drawable="@drawable/add_selection0014" android:duration="50" />
    <item android:drawable="@drawable/add_selection0015" android:duration="50" />
    <item android:drawable="@drawable/add_selection0016" android:duration="50" />
    <item android:drawable="@drawable/add_selection0017" android:duration="50" />
    <item android:drawable="@drawable/add_selection0018" android:duration="50" />
    <item android:drawable="@drawable/add_selection0019" android:duration="50" />
    <item android:drawable="@drawable/add_selection0020" android:duration="50" />
 </animation-list>

here set different images for your sequence animation.set this drawable as your background in imageview

任性一次 2024-10-18 08:33:02

为了让您开始,您可以尝试帧动画,它是 Android 中基本动画包的一部分,官方文档网站上有一个相对简单的示例:http://developer.android.com/guide/topics/resources/animation-resource.html#Frame

如果您需要对动画进行更多控制,则需要考虑使用 SurfaceView 或 Canvas 并自行绘制(动画)。这也不是太难,但您的需求将决定最好的做法是什么。因此,请先尝试帧动画,如果您发现它限制太多,请回发,我(或其他人)可以帮助您开始使用 SurfaceView。

Just to get you going you can try Frame Animation, it's part of the basic Animation package within Android, there is a relatively simple example on the official docs website here: http://developer.android.com/guide/topics/resources/animation-resource.html#Frame.

If you need more control of the animation you'll need to look in to using the SurfaceView or Canvas and do the drawing (animation) yourself. That's not too difficult either but your needs will dictate what the best thing to do is. So try the Frame Animation first, if you find it's too limiting post back and I (or some one else) can help you to get going with SurfaceView.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文