android 的Tween动画并不会改变控件的属性值,比如以下测试片段:

定义一个从屏幕右边进入,滚动到屏幕左边消失的一个TranslateAnimation动画:

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:fillEnabled="true"
android:fillAfter="true">
<translate
android:duration="7000"
android:fromXDelta="100%p"
android:toXDelta="-100%"/>
</set>

在activity里面设置某个TextView的动画,并且另起一个线程每隔一秒获取textView的坐标:

public class Activity1 extends Activity {
private TextView textView;
private Animation animation;
private int location[] = new int[2];
private boolean flags = true;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
animation = AnimationUtils.loadAnimation(this,R.anim.scrollanim);
textView = (TextView)findViewById(R.id.textview);
textView.setOnClickListener(
new TextView.OnClickListener() {
@Override
public void onClick(View v) {
textView.startAnimation(animation);
}
});
getLocationThread.start();
} private Thread getLocationThread = new Thread(){
@Override
public void run() {
while(flags){
textView.getLocationOnScreen(location);
Log.i("test", location[0] + "");
try {
Thread.sleep(1000L);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}; @Override
protected void onDestroy() {
flags = false;
super.onDestroy();
}
}

最后LogCat测试结果如下所示:

可见虽然TextView随着动画移动了,但是他的位置属性并没有改变。

那么如何获取随着动画改变的坐标?

利用Transformation这个类

代码如下所示:

private Thread getLocationThread = new Thread(){
@Override
public void run() {
while(flags){
Transformation transformation = new Transformation();
animation.getTransformation(AnimationUtils.currentAnimationTimeMillis(),transformation);
Matrix matrix = transformation.getMatrix();
float[] matrixVals = new float[9];
matrix.getValues(matrixVals);
Log.i("test", matrixVals[2] + "");
try {
Thread.sleep(1000L);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
};

Matrix是由9个float构成的3X3的矩阵,如下所示:

|cosX  -sinX   translateX|

|sinx   cosX    translateY|

|0         0         scale     |

cosX sinX表示旋转角度,按顺时针方向算。 scale是缩放比例。

启动线程后 LogCat如下所示:

最新文章

  1. hdu-2444-二分图判定+最大分配
  2. 游戏编程技巧 - Subclass Sandbox
  3. libtool: line 990: g++: command not found的解决
  4. CU上看到的一个简单的算法帖子
  5. 腾讯 pc端面试(2015.10.26)
  6. Linux系统常用命令
  7. ZOJ 1610 Count the Colors (线段树区间更新)
  8. Spark shell的原理
  9. linux上TCP connection timeout的原因查找
  10. 常用布局,div竖直居中
  11. Android SDK Manager安装报错
  12. 向.net后端发送请求获取数据,在前端动态填充表格
  13. 性能测试——jmeter环境搭建,录制脚本,jmeter参数化CSV
  14. ZOJ2110 HDU1010 搜索 Tempter of the Bone
  15. 如何使用一次for循环得到数组中第二大的数和第三大的数
  16. 途牛java实习面试(失败)
  17. index.html jquery
  18. 【原创】MIPS相关
  19. B2B、B2C、C2C、O2O 和 P2P 的含义
  20. Hadoop系列-MapReduce基础

热门文章

  1. cesium加载shp格式数据
  2. 【51nod1743】雪之国度(最小生成树+倍增)
  3. Servlet 学习小结
  4. JavaScript 常用的排序算法
  5. jquery淡入淡出轮播图
  6. zabbix监控系统时间的问题
  7. 51nod——2478 小b接水(预处理 思维)
  8. 用JavaScript实现CheckBox的全选取消反选,及遮罩层中添加内容
  9. JavaScript设置div中的文字滚动起来 实现滚动效果
  10. 从Mixin到hooks,谈谈对React16.7.0-alpha中即将引入的hooks的理解