动画 -- 按钮 -- 左右晃动
动画 -- 按钮 左右
2023-09-14 08:58:59 时间
1 import android.view.animation.Animation;
2 import android.view.animation.Transformation;
3
4 public class CustomAnim extends Animation {
5
6 @Override // 获取目标对象的宽高和容器的宽高。
7 public void initialize(int width, int height, int parentWidth,
8 int parentHeight) {
9
10 super.initialize(width, height, parentWidth, parentHeight);
11 }
12
13 @Override
14 protected void applyTransformation(float interpolatedTime, Transformation t) {
15 // interpolatedTime 从0到1,等动画执行完毕后就会变成1。t 变化对象。
16 // System.out.println(interpolatedTime);
17 // t.setAlpha(interpolatedTime);
18 // interpolatedTime 补间动画
19 // t.getMatrix().setTranslate(200*interpolatedTime, 200*interpolatedTime);
20 // 左右摇摆动画(*20运动速度周期 *50表示左右摇摆幅度增大。)
21 t.getMatrix().setTranslate((float) (Math.sin(interpolatedTime*20)*50), 0);
22
23 super.applyTransformation(interpolatedTime, t);
24 }
25
26 }
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
public class MainActivity extends Activity {
private CustomAnim ca;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ca = new CustomAnim();
ca.setDuration(1000);
findViewById(R.id.btnAnimMe).setOnClickListener(
new View.OnClickListener() {
@Override
public void onClick(View arg0) {
arg0.startAnimation(ca);
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
相关文章
- android flash路径动画,Flash制作沿着路径的动画
- android开机动画 制作工具,android开机动画制作
- CSS3 动画 animation
- 关于物理效果的动画引擎 UIDynamic 介绍
- iOS抽奖转盘上篇:概率抽奖算法 & 转盘算法 &轮盘边框动画丨(内含完整Demo)
- 《前端技巧复盘》使用纯css实现网站换肤和焦点图切换动画
- KeyShot动画渲染软件安装包:3D渲染软件KeyShot下载安装
- [android] 帧动画和补间动画详解手机开发
- CSS3 滤镜Filter亮度动画详解编程语言
- jQuery动画的实现原理
- 国产科技动画 提升空间很大
- JS动画效果代码3
- Android开发之图形图像与动画(五)LayoutAnimationController详解
- JQuery动画animate的stop方法使用详解