已不再推荐补间动画,请使用属性动画;
动画中的View的点击判断
Android 动画框架详解
http://www.ibm.com/developerworks/cn/opensource/os-cn-android-anmt1/index.html
每次点击往前100或往后100.
package com.ql.app;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.animation.LinearInterpolator;
import android.view.animation.TranslateAnimation;
import android.widget.Button;
import android.widget.ImageView;
public class App extends Activity {
private Button btn_0,btn_1;
private ImageView iv;
private int count;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
iv = (ImageView)findViewById(R.id.iv);
iv.bringToFront();
btn_0=(Button)findViewById(R.id.btn_0);
btn_0.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
TranslateAnimation animation = new TranslateAnimation(count*100, 100+count*100, 0, 0);
animation.setInterpolator(new LinearInterpolator());
animation.setDuration(400);
animation.setFillAfter(true);
iv.startAnimation(animation);
count++;
}
});
btn_1=(Button)findViewById(R.id.btn_1);
btn_1.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
TranslateAnimation animation = new TranslateAnimation(count*100, -100+count*100, 0, 0);
animation.setInterpolator(new LinearInterpolator());
animation.setDuration(400);
animation.setFillAfter(true);
iv.startAnimation(animation);
count--;
}
});
}
}
android 自定义Animation
http://lipeng88213.iteye.com/blog/1199120
http://www.ophonesdn.com/article/show/185
简单循环动画的实现:
使用:
import android.app.Activity;
import android.os.Bundle;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;
import android.widget.TextView;
public class App extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Animation alpha = AnimationUtils.loadAnimation(this, R.anim.anim_alpha);
Animation translate = AnimationUtils.loadAnimation(this, R.anim.anim_translate);
Animation scale = AnimationUtils.loadAnimation(this, R.anim.anim_scale);
TextView tv=(TextView)findViewById(R.id.tv);
tv.startAnimation(alpha);
ImageView iv0=(ImageView)findViewById(R.id.iv0);
ImageView iv1=(ImageView)findViewById(R.id.iv1);
ImageView iv2=(ImageView)findViewById(R.id.iv2);
iv0.startAnimation(alpha);
iv1.startAnimation(translate);
iv2.startAnimation(scale);
}
}
- 大小: 64 KB
- Test_movement.rar (382 KB)
- 下载次数: 652
- 大小: 18.6 KB
- TestAnimation.zip (185.7 KB)
- 描述: 简单循环动画
- 下载次数: 253
- 查看图片附件
服务器托管,北京服务器托管,服务器租用 http://www.fwqtg.net
机房租用,北京机房租用,IDC机房托管, http://www.e1idc.net