动画效果 :一张小图片以自身中心旋转,从屏幕左边到右边,再到左边,一直运行。(还不知道怎么传动图,以后知道了再传。毕竟这次的动画比较简单)
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); } });运行程序,点击按钮,就可以看到效果了。
本文介绍如何使用Android的XML动画实现一张小图片绕其中心旋转并水平来回移动的动画效果。通过在res/anim目录下创建rotate_test.xml文件,并在MainActivity中调用AnimationUtils加载动画,最终实现无限循环的旋转和平移动画。
4102

被折叠的 条评论
为什么被折叠?



