TranslateAnimation 运行动画后实际位置不正确问题
最近在调试android 动画时候发现一个很奇怪问题,网上搜索都说TranslateAnimation 动画运行后,实际位置要在动画结束的监听里面重新设置才会正确,不然物体位置还是在原位。
我根据网上所说之动画监听里面添加了动画结束监听,设置了物体到新位置,发现物体在视图里面还是错位,
后来经过调试发现,必须在动画结束时候移除动画,然后重新设置位置才会正确
AnimationSet set = new AnimationSet(true);
set.addAnimation(translateAnimation);
set.addAnimation(alpha);
set.setDuration(1000);
set.setFillAfter(true);
texas.startAnimation(set);
set.setAnimationListener(new Animation.AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
}
@Override
public void onAnimationEnd(Animation animation) {
texas.clearAnimation();// 增加这句后,重新设置位置,物体才会移动正确
Log.d(TAG,"end Top:" + texas.getTop() + ",Y:" + texas.getY());
RelativeLayout.LayoutParams paramsTexas = new RelativeLayout.LayoutParams(30,30);
paramsTexas.addRule(RelativeLayout.ALIGN_PARENT_TOP);
paramsTexas.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
if(targetdirect == 0)
{
paramsTexas.setMargins(gridLayout.getLeft() + left + playerPanel.getWidth() / 2,(top + playerPanel.getHeight() + 40),0,0);
}
if(targetdirect == 1)
{
paramsTexas.setMargins((left - 40),top + playerPanel.getHeight() / 2,0,0);
}
if(targetdirect == 2)
{
paramsTexas.setMargins(gridLayout.getLeft() + left + playerPanel.getWidth() / 2,top - 60,0,0);
}
if(targetdirect == 3)
{
paramsTexas.setMargins(gridLayout.getLeft() + left + playerPanel.getWidth() + 40,top + playerPanel.getHeight()/2,0,0);
}
texas.setLayoutParams(paramsTexas);
}
@Override
public void onAnimationRepeat(Animation animation) {
}
});
TranslateAnimation 运行动画后实际位置不正确问题的更多相关文章
- 每日一问:到底为什么属性动画后 View 在新位置还能响应事件
在 Android 开发中,我们难免会使用动画来处理各种各样的动画效果,以满足 UI 的高逼格设计.对于比较复杂的动画效果,我们通常会采用著名的开源库:lottie-android,或许你会对 lot ...
- 运行编译后的程序报错 error while loading shared libraries: lib*.so: cannot open shared object file: No such file or directory
运行编译后的程序报错 error while loading shared libraries: lib*.so: cannot open shared object file: No such f ...
- WPF 控件截图位置不正确的问题
用WPF的RenderTargetBitmap可以截取控件内容到一张图片上,但是实际使用的时候经常出现截取的位置不正确的问题.今天是第二次解决这个问题,所以记录下,免得再忘了. RenderTarge ...
- Xcode6 运行程序后,右侧Debug区域的Memory显示空白解决方法
http://chenyh-blog.com/%E8%9B%8B%E7%96%BC%E7%9A%84%E5%86%85%E5%AD%98-%E7%AC%AC%E4%B8%89%E7%AF%87-sdw ...
- Java学习笔记——Java程序运行超时后退出或进行其他操作的实现
当程序进入死循环或者由于其他原因无法自行终止的时候,就需要强制退出程序了. 对于开发软件 Eclipse ,在程序执行超时后,可以点击 Terminate 按钮强制退出. 那么,我们可不可以通过程序设 ...
- IDEA运行编译后配置文件无法找到,或配置文件修改后无效的问题
1.触发事件 今天正好在学习log4j,为了测试其配置文件log4j.properties中的各种配置,进行了频繁修改和程序启动以确认效果,因为是使用的IDEA建立的Web项目,接着问题就来了,配置文 ...
- Dynamics 365检查工作流、SDK插件步骤是否选中运行成功后自动删除系统作业记录
本人微信公众号:微软动态CRM专家罗勇 ,回复298或者20190120可方便获取本文,同时可以在第一间得到我发布的最新博文信息,follow me!我的网站是 www.luoyong.me . 系统 ...
- Linux下java nohup 后台运行关闭后进程停止的原因,不挂断后台运行命令
Linux下java nohup 后台运行关闭后进程停止的原因,不挂断后台运行命令 今天写sh脚本发现一终止命令程序就停止运行了,检查了很久才发现后面少了个&字符导致的!错误写法:nohup ...
- Eclipse------用Tomcat运行项目后出现:严重: Error configuring application listener of class org.springframework.web.context.ContextLoaderListener
Eclipse中Tomcat运行项目后出现: 严重: Error configuring application listener of class org.springframework.web.c ...
随机推荐
- edittext把软键盘上的回车键改为搜索、发送或者 下一步,窗口随软键盘弹出而改变。
http://m.blog.csdn.net/article/details?id=51350501 以上博文讲解很详细. 如图所示,有时候为了布局美观,在搜索时没有搜索按钮,而是调用软件盘上的按钮. ...
- nodejs笔记
“多读书多看报,少看视频多睡觉.”在2015年即将结束之际,我把这句话作为我2016年的个人签名,希望它能时刻提醒我自己应该去好好读书,查漏补缺,充实自己,遇到不清楚的漏洞就努力去弄懂弄通. 在web ...
- 课程设计 --- 黑白棋中的 AI
原文链接:https://www.dreamwings.cn/reversi/3013.html 到了考试周了佯,可是偏偏这个时候迎来了很多很多的课程设计,幸好教授把C语言的课程设计提前发出了,不然都 ...
- 一个ubuntu phper的自我修养(ubuntu安装)
ubuntu安装篇 一.ubuntu下载 到ubuntu官网下载适合自己电脑配置的系统版本,此处不做展开. 二.制作USB启动盘 在windows下制作USB启动盘,工具是universal usb ...
- jdk 设计模式
摘自:http://blog.csdn.net/bakeloar/article/details/6608806
- ionic imgBase64
navigator.camera.getPicture(onPhotoDataSuccess, onFail, { quality: , destinationType: destinationTyp ...
- python http代理代码
googlecode :https://code.google.com/archive/p/python-proxy/source/default/source # -*- coding: cp125 ...
- BLE编程中关键步骤
获取权限 <uses-permission android:name="android.permission.BLUETOOTH"/> <uses-permiss ...
- redis安装
参考redis.io 安装步骤 下载,编译reids $ wget http://download.redis.io/releases/redis-3.0.6.tar.gz $ tar xzf red ...
- ThinkPHP3.2中if判断条件是两个变量
<select name="typeId"> <foreach name="typeInfo" item="v"> ...