自定义Animation中如何让组件移动至屏幕右下角
2012-04-22 09:59
519 查看
package com.demo; import android.graphics.Camera; import android.graphics.Matrix; import android.view.animation.Animation; import android.view.animation.LinearInterpolator; import android.view.animation.Transformation; public class MyAnimation extends Animation { private int parentWidth; private int parentHeight; private float objectWidth; private float objectHeight; private Camera camera; @Override protected void applyTransformation(float interpolatedTime, Transformation t) { // TODO Auto-generated method stub super.applyTransformation(interpolatedTime, t); Matrix matrix=t.getMatrix(); camera.save(); camera.getMatrix(matrix); //必须写在preTranslate postTranslate方法之前否则达不到想要的效果 matrix.preTranslate(0,0); //动画起始点,默认左上角 matrix.postTranslate((parentWidth-objectWidth)*interpolatedTime, (parentHeight-objectHeight)*interpolatedTime); /* matrix.preTranslate(parentWidth/2,parentHeight/2); matrix.postTranslate((parentWidth/2-objectWidth)*interpolatedTime, (parentHeight/2-objectHeight)*interpolatedTime); */ camera.restore(); } @Override public void initialize(int width, int height, int parentWidth, //width,height表目标组件的尺寸, int parentHeight) { //parentWidth,parentHeight表目的组件的父组件的尺寸 // TODO Auto-generated method stub super.initialize(width, height, parentWidth, parentHeight); setDuration(5000); setFillAfter(false); //设置是否保存动画后的位置,false表示动画后恢复到初始位置 objectHeight=height; objectWidth=width; this.parentWidth=parentWidth; this.parentHeight=parentHeight; camera=new Camera(); setInterpolator(new LinearInterpolator()); //设置动画播放速率 } }本文出自 “Android开发旅程” 博客,请务必保留此出处http://randino.blog.51cto.com/1972239/841044
相关文章推荐
- 如何移动组件的位置,例如如何将UIAlertView显示在屏幕上部
- 如何移动组件的位置,例如如何将UIAlertView显示在屏幕上部
- 如何自定义Shell登录组件
- 如何在自定义数据源组件中为自定义属性提供UIEditor
- 自定义组件+如何让自定义Layout截取Touch事件
- vue-cli中如何创建并引入自定义组件
- 如何控制屏幕(摄像机)移动
- HTML5 UI框架Kendo UI Web中如何创建自定义组件(二)
- unity3d ugui中如何获取ui控件位置?或者说如何将ugui中ui控件(组件)的坐标转化为屏幕坐标或canvas坐标(大坑)?
- (系列2)可视 Mobile 设计器自定义组件:登录屏幕
- android自定义listview,添加监听器,解决屏幕滑动组件状态干扰的问题checkbox
- 在vue2.0中父组件如何触发子组件的自定义方法?
- iPad和iPhone的Safari“添加至主屏幕”功能如何自定义图标
- 如何在自定义数据源组件中为自定义属性提供UIEditor
- 如何让theme是自定义dialog样式的activity横向全屏显示(默认是和普通dialog那样,横向不是布满屏幕的)
- WebApp最佳实践用户体验篇之如何针对多种屏幕尺寸设计合理的移动应用
- Windows Store apps开发[52]Button控件的自定义——模仿开始屏幕中磁贴的按下、移动效果
- vue-cli中如何创建并引入自定义组件
- 如何创建FLEX自定义组件(1)
- COREANIMATION中如何自定义动画属性