Android 四种动画效果的调用

在这里, 我将每种动画分别应用于四个按钮为例:

 (1)  main.xml 代码如下:(声明四个按钮控件)

XML代码:

<?xml version="1.0" encoding="utf-8"?>
<AbsoluteLayout
android:id="@+id/widget32"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
>
<TextView
android:id="@+id/widget29"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"
android:layout_x="0px"
android:layout_y="0px"
>
</TextView>
<Button
android:id="@+id/button_Alpha"
android:layout_width="150px"
android:layout_height="150px"
android:text="Alpha动画"
android:textSize="50px"
android:layout_x="0px" 
android:layout_y="30px">
</Button>
<Button
android:id="@+id/button_Scale"
android:layout_width="150px"
android:layout_height="150px"
android:text="Scale动画"
android:textSize="50px"
android:layout_x="0px" 
android:layout_y="180px">
</Button>
<Button
android:layout_width="150px"
android:layout_height="150px"
android:text="Translate动画"
android:layout_x="161px" 
android:layout_y="30px" 
android:textSize="30px" 
android:id="@+id/button_Translate">
</Button>
<Button
android:id="@+id/button_Rotate"
android:layout_width="150px"
android:layout_height="150px"
android:text="Rotate动画"
android:layout_y="180px" 
android:layout_x="161px" 
android:textSize="44px">
</Button>
</AbsoluteLayout>

java代码:

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.Button;

public class myActionAnimation extends Activity implements OnClickListener {
/** Called when the activity is first created. */
private Button button_alpha;
private Button button_scale;
private Button button_translate;
private Button button_rotate;
private Animation myAnimation_Alpha;
private Animation myAnimation_Scale;
private Animation myAnimation_Translate;
private Animation myAnimation_Rotate;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

button_alpha = (Button) findViewById(R.id.button_Alpha);
button_alpha.setOnClickListener(this);

button_scale = (Button) findViewById(R.id.button_Scale);
button_scale.setOnClickListener(this);

button_translate = (Button) findViewById(R.id.button_Translate);
button_translate.setOnClickListener(this);

button_rotate = (Button) findViewById(R.id.button_Rotate);
button_rotate.setOnClickListener(this);
}
public void onClick(View button) {
// TODO Auto-generated method stub
switch (button.getId()) {
case R.id.button_Alpha: {
myAnimation_Alpha = AnimationUtils.loadAnimation(this,R.layout.my_alpha_action);
button_alpha.startAnimation(myAnimation_Alpha);
}
break;
case R.id.button_Scale: {
myAnimation_Scale= AnimationUtils.loadAnimation(this,R.layout.my_scale_action);
button_scale.startAnimation(myAnimation_Scale);
}
break;
case R.id.button_Translate: {
myAnimation_Translate= AnimationUtils.loadAnimation(this,R.layout.my_translate_action);
button_translate.startAnimation(myAnimation_Translate);
}
break;
case R.id.button_Rotate: {
myAnimation_Rotate= AnimationUtils.loadAnimation(this,R.layout.my_rotate_action);
button_rotate.startAnimation(myAnimation_Rotate);
}
break;

default:
break;
}
}
}

效果图:

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值