package zyf.myAnimation;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.Menu;
import android.view.MenuItem;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnTouchListener;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.Toast;
import android.widget.ViewFlipper;
public class myAnimation extends Activity implements OnClickListener {
/** Called when the activity is first created. */
// private Button button_toTestAnimation;
private Button bt_last, bt_replay, bt_next, bt_list, bt_exit;
protected Animation animation;
private int[] ID;
private MenuItem back_Menu, next_Menu, restart_Menu, selsect_Menu,
exit_Menu;
private final int Back_Menu_ID = Menu.FIRST + 1;
private final int Next_Menu_ID = Menu.FIRST + 2;
private final int Selsect_Menu_ID = Menu.FIRST + 3;
private final int Restart_Menu_ID = Menu.FIRST + 4;
private final int Exit_Menu_ID = Menu.FIRST + 5;
private int the_Animation_ID = 0;
private int i = 0;
private int requestCode = 110;
private Bundle bundle;
ViewFlipper vflipper;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ID = new int[] { R.anim.myanimation_simple, R.anim.my_alpha_action,
R.anim.my_scale_action, R.anim.my_translate_action,
R.anim.my_rotate_action, R.anim.alpha_scale,
R.anim.alpha_translate, R.anim.alpha_rotate,
R.anim.scale_translate, R.anim.scale_rotate,
R.anim.translate_rotate, R.anim.alpha_scale_translate,
R.anim.alpha_scale_rotate, R.anim.alpha_translate_rotate,
R.anim.scale_translate_rotate,
R.anim.alpha_scale_translate_rotate, R.anim.myown_design };
findMyButton();
myButtonSetListener();
vflipper = (ViewFlipper) findViewById(R.id.flipper);
vflipper.addView(addImageById(R.drawable.mb5u10_mb5ucom));
vflipper.addView(addImageById(R.drawable.mb5u14_mb5ucom));
vflipper.addView(addImageById(R.drawable.mb5u12_mb5ucom));
vflipper.setOnTouchListener(new OnTouchListener()
{
public boolean onTouch(View arg0, MotionEvent arg1)
{
// TODO Auto-generated method stub
vflipper.showNext();
return false;
}
});
UpdateMonitor um = new UpdateMonitor(5000);
Thread monitor = new Thread(um);
monitor.start();
}
private void myButtonSetListener() {
// TODO Auto-generated method stub
bt_last.setOnClickListener(this);
bt_replay.setOnClickListener(this);
bt_next.setOnClickListener(this);
bt_list.setOnClickListener(this);
bt_exit.setOnClickListener(this);
// button_toTestAnimation.setOnClickListener(new OnClickListener() {
// public void onClick(View v) {
// // TODO Auto-generated method stub
//
// }
// });
}
private void findMyButton() {
// TODO Auto-generated method stub
// button_toTestAnimation = (Button) findViewById(R.id.Button01);
bt_last = (Button) findViewById(R.id.button_Last);
bt_replay = (Button) findViewById(R.id.button_Replay);
bt_next = (Button) findViewById(R.id.button_Next);
bt_list = (Button) findViewById(R.id.button_List);
bt_exit = (Button) findViewById(R.id.button_Exit);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// TODO Auto-generated method stub
back_Menu = menu.add(0, this.Back_Menu_ID, 1, "上一个动画");
next_Menu = menu.add(0, this.Next_Menu_ID, 2, "下一个动画");
restart_Menu = menu.add(0, this.Restart_Menu_ID, 3, "重新播放");
selsect_Menu = menu.add(0, this.Selsect_Menu_ID, 4, "选择动画");
exit_Menu = menu.add(0, this.Exit_Menu_ID, 5, "退出");
back_Menu.setIcon(R.drawable.ic_menu_back);
next_Menu.setIcon(R.drawable.ic_menu_next);
restart_Menu.setIcon(R.drawable.ic_menu_restart);
selsect_Menu.setIcon(R.drawable.ic_menu_select);
exit_Menu.setIcon(R.drawable.ic_power);
return super.onCreateOptionsMenu(menu);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// TODO Auto-generated method stub
if (item.getItemId() == this.Exit_Menu_ID) {
finish();
} else if (item.getItemId() == this.Selsect_Menu_ID) {
Intent forIntent = new Intent();
forIntent.setClass(myAnimation.this, MYListActivity.class);
startActivityForResult(forIntent, requestCode);
} else {
switch (item.getItemId()) {
case Back_Menu_ID: {
toLastIndex();
}
break;
case Next_Menu_ID: {
toNextIndex();
}
break;
default:
break;
}
load_start_Animation(i);
}
return super.onOptionsItemSelected(item);
}
private void load_start_Animation(int i) {
this.i = i;
the_Animation_ID = ID[i];
if (the_Animation_ID != 0) {
animation = AnimationUtils.loadAnimation(this, the_Animation_ID);
// button_toTestAnimation.startAnimation(animation);
vflipper.startAnimation(animation);
vflipper.showNext();
}
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// TODO Auto-generated method stub
if (requestCode == this.requestCode) {
if (resultCode == RESULT_OK) {
try {
bundle = data.getExtras();
i = bundle.getInt("INDEX");
load_start_Animation(i);
} catch (Exception e) {
// TODO: handle exception
Toast.makeText(this, "ERROR", Toast.LENGTH_LONG).show();
}
} else {
Toast.makeText(this, "返回取消", Toast.LENGTH_LONG).show();
}
} else {
Toast.makeText(this, "无返回!", Toast.LENGTH_LONG).show();
}
}
public void onClick(View v) {
// TODO Auto-generated method stub
if (v.equals(bt_exit)) {
finish();
} else if (v.equals(bt_list)) {
Intent forIntent = new Intent();
forIntent.setClass(myAnimation.this, MYListActivity.class);
startActivityForResult(forIntent, requestCode);
} else {
switch (v.getId()) {
case R.id.button_Last: {
toLastIndex();
}
break;
case R.id.button_Next: {
toNextIndex();
}
break;
default:
break;
}
load_start_Animation(i);
}
}
private void toLastIndex() {
--i;
if (i < 0) {
i = ID.length - 1;
}
}
private void toNextIndex() {
++i;
if (i >= ID.length) {
i = 0;
}
}
public View addImageById(int i)
{
ImageView iv = new ImageView(this);
iv.setImageResource(i);
return iv;
}
public class UpdateMonitor extends Thread {
int time;
public UpdateMonitor(int i){
time = i;
}
@Override
public void run() {
// TODO Auto-generated method stub
while(true){
try
{
sleep(time);
}
catch (InterruptedException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
message.sendEmptyMessage(0);
}
}
}
private Handler message = new Handler(){
public void handleMessage(Message msg) {
the_Animation_ID = ID[i];
if (the_Animation_ID != 0) {
animation = AnimationUtils.loadAnimation(myAnimation.this, the_Animation_ID);
// button_toTestAnimation.startAnimation(animation);
vflipper.startAnimation(animation);
vflipper.showNext();
}
}
};
}
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
史上最全的Android 动画效果.rar (74个子文件)
myAnimation
AndroidManifest.xml 743B
res
anim
alpha_scale_rotate.xml 972B
alpha_rotate.xml 680B
scale_translate.xml 755B
translate_rotate.xml 736B
my_translate_action.xml 873B
myanimation_simple.xml 1KB
alpha_scale_translate_rotate.xml 1KB
my_rotate_action.xml 2KB
myown_design.xml 2KB
alpha_scale_translate.xml 964B
alpha_translate.xml 585B
alpha_translate_rotate.xml 955B
scale_translate_rotate.xml 1KB
my_alpha_action.xml 665B
alpha_scale.xml 801B
my_scale_action.xml 2KB
scale_rotate.xml 847B
layout
list_layout.xml 364B
main.xml 2KB
drawable
favorite2.png 5KB
mb5u7_mb5ucom.png 10KB
mb5u4_mb5ucom.png 19KB
add_to_favorites.png 5KB
mb5u10_mb5ucom.png 6KB
ic_cmd_replay.png 919B
mb5u2_mb5ucom.png 21KB
mb5u3_mb5ucom.png 9KB
ic_menu_restart.png 2KB
ic_menu_next.png 2KB
mb5u8_mb5ucom.png 14KB
ic_cmd_next.png 1KB
ic_menu_select.png 5KB
mb5u14_mb5ucom.png 10KB
mb5u5_mb5ucom.png 19KB
bt_group_back.png 322B
ic_cmd_power.png 925B
mb5u6_mb5ucom.png 9KB
mb5u1_mb5ucom.png 5KB
ic_power.png 925B
ic_cmd_list.png 5KB
mb5u15_mb5ucom.png 22KB
icon.png 3KB
ic_menu_back.png 5KB
mb5u16_mb5ucom.png 25KB
favorite.png 70KB
mb5u12_mb5ucom.png 10KB
back.png 5KB
Thumbs.db 89KB
ic_cmd_last.png 1KB
values
strings.xml 203B
src
zyf
myAnimation
myAnimation.java 7KB
MYListActivity.java 2KB
bin
zyf
myAnimation
myAnimation$UpdateMonitor.class 944B
myAnimation$1.class 1KB
R.class 553B
myAnimation$2.class 943B
R$anim.class 1KB
R$layout.class 420B
R$attr.class 331B
MYListActivity.class 4KB
R$id.class 683B
R$string.class 418B
R$drawable.class 1KB
myAnimation.class 7KB
classes.dex 13KB
resources.ap_ 277KB
myAnimation.apk 287KB
.classpath 273B
assets
default.properties 469B
.settings
org.eclipse.core.resources.prefs 88B
org.eclipse.jdt.core.prefs 203B
.project 814B
gen
zyf
myAnimation
R.java 4KB
共 74 条
- 1
panhuaxiang
- 粉丝: 0
- 资源: 6
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
前往页