在Android上同步翻译 [英] Simultaneous Translations on Android

查看:141
本文介绍了在Android上同步翻译的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要做一些翻译同时在Android上。

I'm trying to do several translations simultaneously on Android.

我有2个或多个按钮的布局(大小相同),当我preSS一个我想要的人搬出的画面。

I have 2 or more buttons on a layout (all the same size), and when i press one i want the others to move out of the screen.

我做了一个测试应用程序尝试实施这种行为。

I've done a test app to try to implement this behaviour.

在这我给自己定上点击一个按钮的侦听器进行测试,是这样的:

On it i've set a listener on click of one button to test, something like:

button.setOnClickListener(new View.OnClickListener() {

public void onClick(View view) {

Button toMove = (Button) findViewById(R.id.button_test2);
Button toMove2 = (Button) findViewById(R.id.button_test3);

AnimationSet set = new AnimationSet(true);

TranslateAnimation anim = new TranslateAnimation(0, -toMove
  .getWidth(), 0, 0);
anim.setFillAfter(true);
anim.setDuration(1000);

toMove.setAnimation(anim);
toMove2.setAnimation(anim);

set.addAnimation(anim);

set.startNow();

}

视图:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent">


     <Button android:id="@+id/button_test" android:layout_width="200px"
    android:layout_height="50px" android:text="@string/hello" />

<Button android:id="@+id/button_test2" android:layout_width="200px"
    android:layout_height="50px" android:text="@string/hello"
     />

<Button android:id="@+id/button_test3" android:layout_width="200px"
    android:layout_height="50px" android:text="@string/hello"
     />

    </LinearLayout>

的事情是,这两个按钮启动动画,微微一后,其他。我读过,这是由于getDelayForView()方法返回各自的不同的延迟。有没有什么办法可以同时移动2个或更多的按钮?

The thing is that the two buttons start the animation, one slightly after the other. I've read that it is due to the getDelayForView() method that returns different delays of each. Is there any way to move 2 or more buttons simultaneously?

谷歌是不是非常有帮助: - \

Google was not very helpful :-\

推荐答案

看来, setAnimation 将实际上可以启动动画,可能是异步的。然而,有可能会在设置动画第二种观点的锁。必须有一个调度程序,因为设置的动画在不同顺序的按钮不会影响的事实,底部1是更快。

Issue:

It seems that setAnimation will acutally start the animation and probably asynchronously. However there might be a lock on setting the animation for the second view. There must be a dispatcher because setting the animation for the buttons in different order does not affect the fact that bottom one is faster.

解决的办法是prevent这个假设的锁通过创建两个单独的动画。

The solution is to prevent this hypothetical lock by creating two individual animations.

public void onClick(View view) {
    Button toMove = (Button) findViewById(R.id.button_test2);
    Button toMove2 = (Button) findViewById(R.id.button_test3);

    TranslateAnimation anim = new TranslateAnimation(0, -toMove
            .getWidth(), 0, 0);
    anim.setFillAfter(true);
    anim.setDuration(1000);

    TranslateAnimation anim2 = new TranslateAnimation(0, -toMove
            .getWidth(), 0, 0);
    anim2.setFillAfter(true);
    anim2.setDuration(1000);

    //THERE IS ONE MORE TRICK

    toMove.setAnimation(anim);
    toMove2.setAnimation(anim2);
}

注意:

//还有一项绝活,您可以添加以下code,以确保它们可以一起移动。 仍然必须在1毫秒左右的滞后。

Note:

In the //THERE IS ONE MORE TRICK, you could add the following code to ensure that they move together. There still must be a lag of 1 millisecond or so.

long time =AnimationUtils.currentAnimationTimeMillis();

//This invalidate is needed in new Android versions at least in order for the view to be refreshed.
toMove.invalidate(); 
toMove2.invalidate();
anim.setStartTime(time);
anim2.setStartTime(time);

这篇关于在Android上同步翻译的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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