android – 具有多个视图同步问题的滑动动画

android – 具有多个视图同步问题的滑动动画,第1张

概述我正在尝试使用两个textviews制作动画.两者都处于相对布局中.动画的功能是留下textview将稍微离开,同时右侧textview也将留下一点点.我试过了: http://nineoldandroids.com/和默认方式. 但对于这两种情况,我在这个过程中都有差距.我已经提出了一个问题,但我没有得到任何积极的答复: Android slider animation is not synch @H_419_0@我正在尝试使用两个textvIEws制作动画.两者都处于相对布局中.动画的功能是留下textvIEw将稍微离开,同时右侧textvIEw也将留下一点点.我试过了:

http://nineoldandroids.com/和默认方式.

但对于这两种情况,我在这个过程中都有差距.我已经提出了一个问题,但我没有得到任何积极的答复:

Android slider animation is not synchronized

NineoldandroIDs代码:

xml文件:

<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:

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",-50).setDuration(duration1).start();          ObjectAnimator.offloat(textVIEw2,100,0).setDuration(duration1).start();          counter++;        }        else {          ObjectAnimator.offloat(textVIEw1,-50,0).setDuration(duration1).start();          ObjectAnimator.offloat(textVIEw2,100).setDuration(duration1).start();          counter--;        }      }    });  }}

我该如何解决?

否则我试图将textvIEw放在第二个textvIEw将在屏幕外的布局中,并使用动画我将移动整个布局.我怎么能像这样制作xml?

解决方法 很抱歉误解了你的问题.

无论如何,你的问题与时间无关.两个动画具有相同的持续时间,但问题是动画区域的大小是不同的.从逻辑上讲,在相同的持续时间内移动较长的距离看起来比移动较小的距离要慢.

例如,为了解决您的问题,我在OnClickListener中使用了以下代码:

public voID onClick(VIEw v) {    int wIDth =textVIEw2.getWIDth();    if (counter == 0) {        textVIEw2.setVisibility(VIEw.VISIBLE);        ObjectAnimator.offloat(textVIEw1,-1*wIDth).setDuration(duration1).start();        ObjectAnimator.offloat(textVIEw2,1*wIDth,0).setDuration(duration1).start();        counter++;    }    else {        ObjectAnimator.offloat(textVIEw1,-1*wIDth,0).setDuration(duration1).start();        ObjectAnimator.offloat(textVIEw2,1*wIDth).setDuration(duration1).start();        counter--;    }}
总结

以上是内存溢出为你收集整理的android – 具有多个视图同步问题的滑动动画全部内容,希望文章能够帮你解决android – 具有多个视图同步问题的滑动动画所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/1141085.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-31
下一篇2022-05-31

发表评论

登录后才能评论

评论列表(0条)

    保存