博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
动画 -- 按钮 -- 左右晃动
阅读量:7106 次
发布时间:2019-06-28

本文共 2316 字,大约阅读时间需要 7 分钟。

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     @Override14     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);    }}

 

转载地址:http://kxphl.baihongyu.com/

你可能感兴趣的文章
【移动开发】Android Animation 动画效果总结
查看>>
div的显示和隐藏
查看>>
关于员工的个人职业发展
查看>>
MyBatis整体架构
查看>>
摄影技术基础(四)
查看>>
大型企业网络配置系列课程详解(一)---OSPF单区域配置与相关概念的理解
查看>>
Exported activity does not require permission
查看>>
UIMovieClip的一点小认识(转载)
查看>>
OpenStack 企业私有云的若干需求(10):OpenStack 的前景和钱景
查看>>
ASP.NET免费服务器~支持MVC和Net4.5
查看>>
StackOverflow发布年度开发者调查报告:JavaScript备受欢迎
查看>>
自平衡二叉查找树
查看>>
shell脚本中的数据传递方式
查看>>
Shiro系列(0) - 权限管理在J2EE企业级开发中的应用与实战
查看>>
Oracle Goldengate REPLICAT启动时报正在运行解决办法
查看>>
Gdevops峰会归来
查看>>
[20170215]ORA-00088与DG Gap监测与解决4
查看>>
Hadoop Pig学习笔记(一) 各种SQL在PIG中实现
查看>>
充分挖掘大数据资源“富矿”
查看>>
oerr的用法
查看>>