0
点赞
收藏
分享

微信扫一扫

自定义动画播放


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);
}

 

举报

相关推荐

0 条评论