Android的动画,移动和旋转的同时 [英] Android animation, moving and rotating at same time

查看:209
本文介绍了Android的动画,移动和旋转的同时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我工作的动画图像视图和向右移动并旋转的同时。我能获得该项目利用移动

I am working on animating an image view and that moves to the right and rotates at the same time. I can get the item to move using

    animation = new TranslateAnimation(0, level, 0, 0);
animation.setDuration(1000);
animation.setRepeatCount(0);
animation.setFillAfter(true);

等级是我当时定义的变量。我知道$ C $下旋转。

Level is the variable I have defined at the time. I know the code for rotate is

RotateAnimation rotate = new RotateAnimation(0,rotate,0,0);
    rotate.setDuration(1000);
    rotate.setRepeatCount(0);
    animation.setFillAfter(true);
    bPick.setAnimation(rotate);

再次旋转是可变的我已经在上面定义的。

Again rotate is variable I have defined at the top.

我的问题是,我该如何结合这两种?我已经使用一个线程试图

My question is, how do I combine these two? I have tried using a thread

    private Runnable myThread = new Runnable() {

    @Override
    public void run() {
        while (level < 100) {
            try {
                myHandle.sendMessage(myHandle.obtainMessage());
                Thread.sleep(15);
            } catch (Throwable t) {
            }
        }

    }

    Handler myHandle = new Handler() {

        @Override
        public void handleMessage(Message msg) {

            level++;
            animation = new TranslateAnimation(0, level, 0, 0);
            animation.setDuration(1000);
            animation.setRepeatCount(0);
            animation.setFillAfter(true);
            bPick.setAnimation(animation);

        }
    };
};

这将其移动到右侧正常,但是如果我轮流尝试添加为好,它不工作,否则就会崩溃。

That will have it move to the right fine, however if I try adding in rotation as well, it doesnt work, or it will crash.

任何帮助将是非常美联社preciated,欢呼声

Any help would be much appreciated, cheers

修改

我需要这样做的原因是,我有一个接一个标尺。

The reason I require this is that I have a gauge with a pick.

我需要规挑向右移动,同时慢慢地向右旋转。多少它移动到右侧是基于int变量的设置。它会从0往 - 100。0是起始位置和100,它将被移动到右侧,看起来像这样

I require the gauge pick to move to the right while slowly rotating to the right. How much it moves to the right is based on a int variable set up. It will go from 0 - 100. 0 being the start position and 100, it will be moved to the right and look like this

推荐答案

您需要使用<一个href="http://developer.android.com/reference/android/view/animation/AnimationSet.html">AnimationSet.

而移动的图像从XML我做了一个例子从左向右,向上和向下旋转,都在同一时间。

An example in XML I made which moves an image from left to right, up and down and rotates, all at the same time.

<set xmlns:android="http://schemas.android.com/apk/res/android">
    <!-- Rotate -->
    <rotate android:fromDegrees="30" android:toDegrees="0"
        android:pivotX="50%" android:pivotY="50%" android:repeatCount="4"
        android:repeatMode="reverse" android:duration="2000"
        android:interpolator="@android:anim/linear_interpolator" />
    <!--  Left to right -->
    <translate android:fromXDelta="-50%p" android:toXDelta="150%p"
        android:fromYDelta="100%p" android:toYDelta="0" android:duration="10000"
        android:interpolator="@android:anim/linear_interpolator" />
    <!--  Up and down bob -->
    <translate android:fromXDelta="0" android:toXDelta="0"
        android:fromYDelta="30" android:toYDelta="-30" android:repeatMode="reverse"
        android:repeatCount="4" android:interpolator="@android:anim/linear_interpolator"
        android:duration="2000" />
</set>

code例子(没有重复以上):

Code example (not to replicate above):

AnimationSet animationSet = new AnimationSet(true);

TranslateAnimation a = new TranslateAnimation(
        Animation.ABSOLUTE,200, Animation.ABSOLUTE,200,
        Animation.ABSOLUTE,200, Animation.ABSOLUTE,200);
a.setDuration(1000);    

RotateAnimation r = new RotateAnimation(0f, -90f,200,200);
r.setStartOffset(1000);
r.setDuration(1000);

animationSet.addAnimation(a);
animationSet.addAnimation(r);

(从<一个拍摄href="http://stackoverflow.com/questions/4977138/full-example-of-how-to-programmatically-do-rotateanimations">here)

这篇关于Android的动画,移动和旋转的同时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆