zoukankan      html  css  js  c++  java
  • Android开发UI之自定义动画

    自定义动画,需要新建一个类,继承Animation类。

    重写applyTransformation()方法和initialize()方法。

    applyTransformation(float interpolatedTime, Transformation t)方法中

    第一个参数:interpolatedTime代表动画的时间进行比。不管动画实际的持续时间如何,当动画播放时,该参数总是自动从0变化到1.

    第二个参数:Transformation t代表了补间动画在不同时刻对图形或组件的变形程度。

    button实现左右晃动效果

    自定义的动画

     1 public class CustomAnim extends Animation {
     2     
     3     @Override
     4     public void initialize(int width, int height, int parentWidth,
     5             int parentHeight) {
     6         super.initialize(width, height, parentWidth, parentHeight);
     7     }
     8     
     9     @Override
    10     protected void applyTransformation(float interpolatedTime, Transformation t) {
    11         t.getMatrix().setTranslate((float) Math.sin(interpolatedTime*50)*50,0);
    12         
    13         super.applyTransformation(interpolatedTime, t);
    14     }
    15 
    16 }

    MainActivity中的button点击效果设置

     1 public class MainActivity extends Activity {
     2     
     3     private CustomAnim ca;
     4 
     5     @Override
     6     protected void onCreate(Bundle savedInstanceState) {
     7         super.onCreate(savedInstanceState);
     8         setContentView(R.layout.activity_main);
     9         
    10         ca=new CustomAnim();
    11         ca.setDuration(1000);
    12         
    13         findViewById(R.id.btnAnimationMe).setOnClickListener(new OnClickListener() {
    14             
    15             @Override
    16             public void onClick(View v) {
    17                 // TODO Auto-generated method stub
    18                 v.setAnimation(ca);
    19             }
    20         });
    21     }
    22 }
  • 相关阅读:
    1363:小球(drop)
    ifstream ofstream c++中读写文件
    线性筛
    Network of Schools POJ
    Beautiful numbers CodeForces
    ipone6界面设计标准
    目前的前端框架有哪些
    什么是react native
    nth-child() 选择器
    html{height:100%}的意义以及body背景色的解析推断
  • 原文地址:https://www.cnblogs.com/liyiran/p/4651346.html
Copyright © 2011-2022 走看看