您的位置:首页 > 其它

动画的简单应用

2016-10-12 18:05 330 查看


红点代表pointx,pointy分别是0,0

rotate,scale 的属性

android:pivotX=”0%”

android:pivotY=”0%”

都在红点出发生变化

动画的基本用法:

package com.example.animation;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.Button;
import android.widget.ImageView;

public class MainActivity extends AppCompatActivity implements View.OnClickListener{
private Button scale;
private Button alpha;
private Button rotate;
private Button translate;
private ImageView image;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
scale = (Button) findViewById(R.id.scale);
alpha =(Button) findViewById(R.id.alpha);
rotate =(Button)findViewById(R.id.rotate);
translate = (Button) findViewById(R.id.translate);
translate.setOnClickListener(this);
rotate.setOnClickListener(this);
alpha.setOnClickListener(this);
scale.setOnClickListener(this);
image = (ImageView) findViewById(R.id.image);
}

@Override
public void onClick(View v) {
Animation loadAnimation;
switch (v.getId()){
case R.id.scale: {
loadAnimation = AnimationUtils.loadAnimation(this, R.anim.scale);
image.startAnimation(loadAnimation);
break;
}

case R.id.alpha: {
loadAnimation = AnimationUtils.loadAnimation(this, R.anim.alpha);
image.startAnimation(loadAnimation);
break;
}

case R.id.rotate: {
loadAnimation = AnimationUtils.loadAnimation(this, R.anim.rotate);
image.startAnimation(loadAnimation);
break;
}

case R.id.translate: {
loadAnimation = AnimationUtils.loadAnimation(this, R.anim.translate);
image.startAnimation(loadAnimation);
break;
}
}
}
}


<?xml version="1.0" encoding="utf-8"?>
<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"
>

<Button
android:id="@+id/scale"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="ScaleAnimation(缩放动画)" />
<Button
android:id="@+id/alpha"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="AlphaAnimation(透明度动画)" />

<Button
android:id="@+id/rotate"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="RotateAnimation(旋转动画)" />

<Button
android:id="@+id/translate"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="TranslateAnimation(位移动画)" />

<ImageView
android:id="@+id/image"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_gravity="center"
android:src="@mipmap/ic_launcher" >
</ImageView>
</LinearLayout>


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

<translate
android:duration="1000"
android:fromXDelta="0"
android:fromYDelta="0"
android:toXDelta="100"
android:toYDelta="100" />

</set>


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

<rotate
android:duration="1000"
android:fromDegrees="0"
android:interpolator="@android:anim/accelerate_decelerate_interpolator"
android:pivotX="0%"
android:pivotY="0%"
android:toDegrees="+360" />

</set>


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

<alpha
android:duration="1000"
android:fromAlpha="0.1"
android:toAlpha="1.0" >
</alpha>

</set>


<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" >

<scale

b660
android:duration="2000"
android:fillAfter="false"
android:fromXScale="0.0"
android:fromYScale="0.0"
android:interpolator="@android:anim/accelerate_decelerate_interpolator"
android:pivotX="0%"
android:pivotY="0%"
android:toXScale="1.0"
android:toYScale="1.0" />
<!--pivotX,pivotY相对于x,y周的位置 50%,50% 为中心-->

</set>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: