简单动画

动画效果  :一张小图片以自身中心旋转,从屏幕左边到右边,再到左边,一直运行。(还不知道怎么传动图,以后知道了再传。毕竟这次的动画比较简单)

1、首先在res文件夹下新建文件夹anim,在anim文件夹下新建一个XML。rotate_test.xml

<set xmlns:android="http://schemas.android.com/apk/res/android">

    <rotate
        android:interpolator="@android:anim/linear_interpolator"
        android:fromDegrees="0"
        android:toDegrees="+360"
        android:pivotX="50%"
        android:pivotY="50%"
        android:repeatCount="-1"
        android:duration="3000"
        />

    <translate
        android:fromXDelta="15"
        android:toXDelta="250"
        android:fromYDelta="70"
        android:toYDelta="70"
        android:duration="10000"
        android:repeatCount="-1"
        android:repeatMode="reverse"
        />
    
</set>

在布局xml里面,有个按钮,有个小图片

        imageView = (ImageView)findViewById(R.id.imageView);
        button = (Button) findViewById(R.id.button3);
        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Animation animation = AnimationUtils.loadAnimation(MainActivity.this, R.anim.rotate_test);
//                //设置为匀速
        LinearInterpolator lin = new LinearInterpolator();
                animation.setInterpolator(lin);
                imageView.startAnimation(animation);
            }
        });
运行程序,点击按钮,就可以看到效果了。


猜你喜欢

转载自blog.csdn.net/ming_csdn_/article/details/59529210