有多个视图同步化的问题,滑动动画 [英] Sliding animation having multiple views syncronization issue

查看:173
本文介绍了有多个视图同步化的问题,滑动动画的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图做一个动画有两个textviews.Both是在动画的相对布局。功能留下的TextView会留下点点,同时正确的TextView还将赴点点left.I有尝试: -

I am trying to make an animation with two textviews.Both are in a relative layout.The functionality of the animation is left textview will go little bit left and at the same time right textview will also go little bit left.I have tried:-

http://nineoldandroids.com/ 并默认方式。

http://nineoldandroids.com/ and default way.

但不管情况下,我得到process.I在间隙已经提出一个问题,但我没有得到任何肯定的答复: -

But for both case I am getting a gap during the process.I already put one question but i am not getting any positive reply:-

<一个href=\"http://stackoverflow.com/questions/19569234/android-slider-animation-is-not-synchronized\">Android滑块动画是不同步的

Nineoldandroids code:

Nineoldandroids code:

XML文件: -

xml file:-

 <RelativeLayout  
android:layout_width="match_parent" android:layout_height="wrap_content"  
android:orientation="horizontal"
android:layout_below="@+id/target"
android:layout_marginTop="50dp"> 

<TextView
    android:id="@+id/TextView01"
    android:layout_width="match_parent"
    android:layout_height="50dp"
    android:layout_alignParentLeft="true"     
    android:background="#f00"
    android:gravity="center"
    android:text="RED"
    android:textColor="#000" />

<Button
        android:id="@+id/TextView02"
        android:layout_width="50dp"
        android:layout_height="match_parent"
        android:layout_alignBottom="@+id/TextView01"
        android:layout_alignParentRight="true"
        android:layout_alignTop="@+id/TextView01"
        android:background="#0F0"
        android:text="TXT"
        android:visibility="invisible" />
</RelativeLayout>

MainActivity.java: -

MainActivity.java :-

public class MainActivity extends Activity {
  double counter = 0;
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.toggles);
    final View target = findViewById(R.id.target);
    final int duration = 5*1000;
    final int duration1 = 300;

    final View textView1 = findViewById(R.id.TextView01);
    final View textView2 = findViewById(R.id.TextView02);
    textView1.setOnClickListener(new View.OnClickListener() {
      @Override
      public void onClick(View v) {
        if (counter == 0) {
          textView2.setVisibility(View.VISIBLE);
          ObjectAnimator.ofFloat(textView1, "translationX", 0, -50).setDuration(duration1).start();
          ObjectAnimator.ofFloat(textView2, "translationX", 100, 0).setDuration(duration1).start();
          counter++;

        }
        else {
          ObjectAnimator.ofFloat(textView1, "translationX", -50,0).setDuration(duration1).start();
          ObjectAnimator.ofFloat(textView2, "translationX", 0,100).setDuration(duration1).start();
          counter--;
        }
      }
    });
  }
}

我该如何解决?

How can i fix it ?

否则我试图把双方的TextView的布局里面,其中第二次的TextView将外屏幕,并使用动画我将撬动整个layout.how我可以做这样的XML?

otherwise i am trying to put both textview inside a layout where second textview will be outside the screen and using the animation i will move the whole layout.how can i make the xml like this?

推荐答案

对不起,误解你的问题。

Sorry for misunderstanding your question.

总之,你的问题不在于准确的时间。两者的动画具有相同的持续时间,但问题是动画区域的大小是不同的。逻辑上,在相同的持续时间移动更长的距离看起来比移动一较小的距离越慢。

Anyway, your issue is not about time exactly. Both animations have the same duration but the problem is the sizes of the animated regions are different. Logically, moving a longer distance in the same duration will look slower than moving a smaller distance.

例如,解决你的问题,我用下面的code。在OnClickListener:

For example, to solve your problem, I used the following code in the OnClickListener:

public void onClick(View v) {
    int width =textView2.getWidth();
    if (counter == 0) {
        textView2.setVisibility(View.VISIBLE);
        ObjectAnimator.ofFloat(textView1, "translationX", 0, -1*width).setDuration(duration1).start();
        ObjectAnimator.ofFloat(textView2, "translationX", 1*width, 0).setDuration(duration1).start();
        counter++;

    }
    else {
        ObjectAnimator.ofFloat(textView1, "translationX", -1*width, 0).setDuration(duration1).start();
        ObjectAnimator.ofFloat(textView2, "translationX", 0, 1*width).setDuration(duration1).start();
        counter--;
    }
}

这篇关于有多个视图同步化的问题,滑动动画的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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