【问题标题】:Animation: Move ImageButton horizontal and vertical动画:水平和垂直移动 ImageButton
【发布时间】:2017-01-23 09:27:13
【问题描述】:

我的 ImageButton 正确地水平移动。但我想水平和垂直移动。 然后重复。

move.xml

<?xml version="1.0" encoding="utf-8"?>
<set
xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/linear_interpolator"
android:fillBefore="true"
android:repeatMode="reset">

<translate
    android:fromXDelta="0%p"
    android:toXDelta="70%p"
    android:duration="2000" />

</set>

hand_motion.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#aa000000"
android:id="@+id/VHandLevel">

<ImageButton
    android:layout_width="100dp"
    android:layout_height="100dp"
    android:id="@+id/ibtnHandLevel"
    android:background="@drawable/hand1"
    android:layout_marginTop="80dp" />

</RelativeLayout>

如果我在 move.xml 中添加这一行:

android:toYDelta="70%p"

它将沿对角线移动。但我想先水平移动,然后垂直移动也会重复。

MainActivity.java

的部分代码
ImageButton iBtnHelp = (ImageButton)dialog.findViewById(R.id.ibtnHandLevel);
    Animation animation1 =
            AnimationUtils.loadAnimation(getApplicationContext(), R.anim.move);
    animation1.setRepeatCount(20);
    iBtnHelp.startAnimation(animation1);

【问题讨论】:

    标签: android animation move imagebutton


    【解决方案1】:

    如果您像这样以编程方式创建动画实例:

    Animation animation = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.move);
    

    然后您可以将计数器设置为多次重复相同的动画 随心所欲:

    animation.setRepeatCount(10);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-07-13
      • 1970-01-01
      • 2012-04-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多