Android 旋转动画

发布于 2024-12-13 10:45:30 字数 264 浏览 1 评论 0原文

我有一个如下所示的布局:(没有箭头)

layout

布局周围动物的图片。 我想制作一个旋转动画,以便所有动物都会朝该方向移动 箭头(实际上,它们应该能够围绕视图旋转 360 度)并替换彼此的位置。但要保持自己的方向——这样每只动物都会继续用腿站立,而不是用头:-)

我已经被这个问题困扰了两天了,我不知道如何实现这个,

请帮忙吗? 谢谢你, 罗恩

i have a layout that looks like this: (without the arrows)

layout

the pictures of the animals around the layout.
i want to make a rotating animation so that all the animals will go to to the direction
of the arrows (actually, they should be able to rotate 360 around the view) and replace each other's location. BUT keep their own orientation - so that every animal will keep standing on her legs, and not her head :-)

I'm stuck with this problem for 2 days now, and i have no idea how to implement this

please any help?
Thank you,
Ron

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

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

发布评论

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

评论(1

人海汹涌 2024-12-20 10:45:30

您可以手动设置它们的动画,就像游戏精灵一样。另一种选择是反对旋转动画:

rotate_left.xmlrotate_right.xml

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
    <rotate
            android:toDegrees="0"
            android:fromDegrees="359"
            android:pivotX="50%"
            android:pivotY="50%"
            android:duration="2000"
            android:repeatCount="infinite"
            android:interpolator="@android:anim/linear_interpolator"
            />
</set>

布局

<set xmlns:android="http://schemas.android.com/apk/res/android">
    <rotate
            android:toDegrees="359"
            android:fromDegrees="0"
            android:pivotX="50%"
            android:pivotY="50%"
            android:duration="2000"
            android:repeatCount="infinite"
            android:interpolator="@anim/lin"
            />
</set>

xml文件(只是顶部和底部的文本框。您必须自己实现4个角;)

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:layout_width="fill_parent"
              android:layout_height="fill_parent"
        android:orientation="horizontal">
    <FrameLayout
            android:layout_width="200dp"
            android:layout_height="200dp"
            android:id="@+id/outer"
            >
        <LinearLayout
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:orientation="vertical"
                android:gravity="center">
            <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:gravity="center"
                    android:id="@+id/top"
                    android:text="Top"/>
            <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:gravity="center"
                    android:id="@+id/bottom"
                    android:text="Bottom"/>


        </LinearLayout>

    </FrameLayout>

</LinearLayout>

在您的活动中:

public void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.[yourlayout]);

    findViewById(R.id.outer).startAnimation(AnimationUtils.loadAnimation(this,R.anim.rotate_left));
    findViewById(R.id.top).startAnimation(AnimationUtils.loadAnimation(this,R.anim.rotate_right));
    findViewById(R.id.bottom).startAnimation(AnimationUtils.loadAnimation(this,R.anim.rotate_right));
}

出于某种原因我不能进行旋转以正确使用线性插值器。它不断加速/减速。可能必须在代码中做到这一点。

You could manually animate them, like game sprites. Another option would be opposing rotate animations:

rotate_left.xml

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
    <rotate
            android:toDegrees="0"
            android:fromDegrees="359"
            android:pivotX="50%"
            android:pivotY="50%"
            android:duration="2000"
            android:repeatCount="infinite"
            android:interpolator="@android:anim/linear_interpolator"
            />
</set>

rotate_right.xml

<set xmlns:android="http://schemas.android.com/apk/res/android">
    <rotate
            android:toDegrees="359"
            android:fromDegrees="0"
            android:pivotX="50%"
            android:pivotY="50%"
            android:duration="2000"
            android:repeatCount="infinite"
            android:interpolator="@anim/lin"
            />
</set>

Layout xml file (just a text box on top and bottom. You'll have to implement the 4 corners yourself ;)

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:layout_width="fill_parent"
              android:layout_height="fill_parent"
        android:orientation="horizontal">
    <FrameLayout
            android:layout_width="200dp"
            android:layout_height="200dp"
            android:id="@+id/outer"
            >
        <LinearLayout
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:orientation="vertical"
                android:gravity="center">
            <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:gravity="center"
                    android:id="@+id/top"
                    android:text="Top"/>
            <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:gravity="center"
                    android:id="@+id/bottom"
                    android:text="Bottom"/>


        </LinearLayout>

    </FrameLayout>

</LinearLayout>

In your Activity:

public void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.[yourlayout]);

    findViewById(R.id.outer).startAnimation(AnimationUtils.loadAnimation(this,R.anim.rotate_left));
    findViewById(R.id.top).startAnimation(AnimationUtils.loadAnimation(this,R.anim.rotate_right));
    findViewById(R.id.bottom).startAnimation(AnimationUtils.loadAnimation(this,R.anim.rotate_right));
}

For some reason I can't get the rotate to use the linear interpolator properly. It keeps speeding up/slowing down. Might have to do that in code.

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