1.新建一anim文件夹,里面建立一myanim.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<alpha
android:fromAlpha="0.1"
android:toAlpha="1.0"
android:duration="2000"
/> <!-- 透明度的转换 -->
<scale
android:interpolator="@android:anim/accelerate_decelerate_interpolator"
android:fromXScale="0.0"
android:toXScale="1.4"
android:fromYScale="0.0"
android:toYScale="1.4"
android:pivotX="50%"
android:pivotY="50%"
android:fillAfter="false"
android:duration="3000"
/> <!-- 尺寸的变换 -->
<translate
android:fromXDelta="30"
android:toXDelta="0"
android:fromYDelta="30"
android:toYDelta="50"
android:duration="3000"
/> <!-- 位置的变换 -->
<rotate
android:interpolator="@android:anim/accelerate_decelerate_interpolator"
android:fromDegrees="0"
android:toDegrees="+350"
android:pivotX="50%"
android:pivotY="50%"
android:duration="3000"
/> <!-- 旋转变换 -->
</set>
2.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="wyf.ytl.MainActivity" >
<ImageView
android:id="@+id/myImageView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@drawable/img"
/>
</LinearLayout>
3.
public class MainActivity extends ActionBarActivity {
Animation myAnimation = null;
ImageView myImageView = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//加载动画
myAnimation = AnimationUtils.loadAnimation(this, R.anim.myanim);
myImageView = (ImageView) findViewById(R.id.myImageView);
//启动动画
myImageView.startAnimation(myAnimation);
}
本文介绍了一种在Android中创建复杂视图动画的方法。通过XML定义了一组包含透明度、尺寸、位置及旋转变化的动画序列,并在Java代码中演示了如何加载并应用这些动画到ImageView上。
9566

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



