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 ...
随机推荐
- java中递归的方法的实例
package com.demo.recursion; // 所谓递归,是指程序调用自身,当然,递归不会无休止地调用下去,它必然有一个出口,当满足条件时程序也就结束了,不然的话,那就是死循环了.// ...
- [转]Java中Map的用法详解
转载地址:http://www.zhixing123.cn/jsp/30113.html Map简介 将键映射到值的对象.一个映射不能包含重复的键:每个键最多只能映射到一个值.此接口取代 Dictio ...
- ORACLE表的恢复
对误删的表,只要没有使用PURGE永久删除选项,那么从flash back区恢复回来希望是挺大的.一般步骤有: 1.从flash back里查询被删除的表 select * from ...
- 瘋耔java语言笔记
一◐ java概述 1.1 ...
- 2016年12月27日 星期二 --出埃及记 Exodus 21:22
2016年12月27日 星期二 --出埃及记 Exodus 21:22 "If men who are fighting hit a pregnant woman and she gives ...
- 添加 index_combine hint的索引
想试验一下 index_combine这个hint,于是做了如下试验. 1.创建一个具有若干index的表 SQL> create table test as select object_id, ...
- Android Studio 2.0使用指南
一.下载界面.[无激活码 无序列码 无毒请放心使用][需将JAVA程序升级到1.8] 网址:http://www.android-studio.org/index.php/download/andro ...
- C# 关于委托和事件的妙文:通过一个例子详细介绍委托和事件的作用;Observer模式简介
委托和事件在 .Net Framework中的应用非常广泛,然而,较好地理解委托和事件对很多接触C#时间不长的人来说并不容易.它们就像是一道槛儿,过了这个槛的人,觉得真是太容易了,而没有过去的人每次见 ...
- What is the difference between routine , method , procedure , function ? please explain it with example?
a method is named and attached to an object. so, for example, a method is like a function but is con ...
- vnc连接kali 2.0 报错:A problem has occurred and the system can't recover.
kali版本: root@kali:~# uname -a Linux kali -kali1-amd64 # SMP Debian -7kali2 (--) x86_64 GNU/Linux 第一步 ...