- 浏览: 227673 次
- 性别:
- 来自: 镇江
文章分类
最新评论
-
Luozii:
安卓8.0的system.img死活解不开。http://s ...
yaffs文件打包解包工具 -
不是流氓兔:
不用设置代理了,现在官网有中文站了 http://www.my ...
myeclipse官方网站打不开解决办法 -
nicekwell:
MNC也有3位的,但我国都是2位
IMSI , MCC MNC 的概念 -
hxy1000:
android里没有模态,不过有的对话框效果类似于模态
android 模态与非模态对话框实现 -
lyx0206331:
...
window adb 安装以及usb驱动
animation 在android 系统中,是一种帧动画,前段时间遇到一个问题就是,一个完整的动画分为两部分,前面一部分,只播放一次,而后面一部分要循环播放。
第一反应,是分两个动画来做,第一部分,播放完后(仅一次),再播放后面一部分,这样来做可能有个衔接问题(没试过,有兴趣的朋友可以试一下)
后来,还是采用一个动画来做。这其中用到了java中的反射,取得了DrawableAnimation中的私有成员变量mCurFrame来记录当前帧。
具体代码,大家可以参考如下:
(1)自定义一个ImageView
主界面代码如下:
完整的实例代码在压缩包中!
第一反应,是分两个动画来做,第一部分,播放完后(仅一次),再播放后面一部分,这样来做可能有个衔接问题(没试过,有兴趣的朋友可以试一下)
后来,还是采用一个动画来做。这其中用到了java中的反射,取得了DrawableAnimation中的私有成员变量mCurFrame来记录当前帧。
具体代码,大家可以参考如下:
(1)自定义一个ImageView
package com.archermin.animationtest; import android.content.Context; import android.graphics.Canvas; import android.graphics.drawable.AnimationDrawable; import android.util.AttributeSet; import android.util.Log; import android.widget.ImageView; import java.lang.reflect.Field; public class MyAnimationImageView extends ImageView { public AnimationDrawable mAnimationDrawable; public Field field; public MyAnimationImageView(Context context, AttributeSet attrs) { super(context, attrs); // TODO Auto-generated constructor stub } @Override protected void onDraw(Canvas canvas) { // TODO Auto-generated method stub super.onDraw(canvas); try{ field = AnimationDrawable.class.getDeclaredField("mCurFrame"); field.setAccessible(true); int curFrame = field.getInt(mAnimationDrawable); Log.d("anim", "curFrame is : " + curFrame); if(curFrame == 17){ field.setInt(mAnimationDrawable, 6); Log.d("anim","set current animation is 6"); } }catch(Exception e){ e.printStackTrace(); } } }
主界面代码如下:
package com.archermin.animationtest; import android.app.Activity; import android.content.Context; import android.graphics.Color; import android.graphics.drawable.AnimationDrawable; import android.graphics.drawable.Drawable; import android.os.Bundle; import android.os.Handler; import android.util.Log; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.ImageView; public class AnimationTest extends Activity implements OnClickListener { /** Called when the activity is first created. */ private Context mContext; private AnimationDrawable mDownloadImageAnim; public static final String TAG = "AnimationTest"; private Button btStart; private Button btStop; private Handler mHandler; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); mContext = this; btStart = (Button)findViewById(R.id.bt_start); btStart.setOnClickListener(this); btStop = (Button)findViewById(R.id.bt_stop); btStop.setOnClickListener(this); mDownloadImageAnim = (AnimationDrawable)mContext.getResources().getDrawable(R.anim.download_dialog_animation); MyAnimationImageView imageView = (MyAnimationImageView)findViewById(R.id.download_image); imageView.setBackgroundDrawable(mDownloadImageAnim); imageView.mAnimationDrawable = mDownloadImageAnim; mHandler = new Handler(); } @Override protected void onResume() { // TODO Auto-generated method stub super.onResume(); mHandler.postDelayed(new StartAnimationRunnable(),500); } private class StartAnimationRunnable implements Runnable{ @Override public void run() { // TODO Auto-generated method stub startAnimation(); } } private class StopAnimationRunnable implements Runnable{ @Override public void run() { stopAnimation(); } } private void startAnimation(){ if(mDownloadImageAnim != null){ mDownloadImageAnim.stop(); Log.d(TAG, "start animation "); mDownloadImageAnim.start(); } } private void stopAnimation(){ if(mDownloadImageAnim != null){ Log.d(TAG, "stop animation "); mDownloadImageAnim.stop(); } } @Override public void onClick(View v) { // TODO Auto-generated method stub switch (v.getId()) { case R.id.bt_start: startAnimation(); break; case R.id.bt_stop: stopAnimation(); break; default: break; } } }
完整的实例代码在压缩包中!
- AnimationMutil.rar (406 KB)
- 下载次数: 6
发表评论
-
Java 理论与实践: 正确使用 Volatile 变量
2014-11-05 17:58 679转自http://www.ibm.com/developerw ... -
linux andorid apk 反编译
2012-11-19 22:02 1458反编译apk 代码 1.下载dex2jar 反编译源码 jdg ... -
window adb 安装以及usb驱动
2012-06-27 22:32 52751.在windows下安装adb 将附件解压,system3 ... -
jni 入门实例
2012-06-10 22:15 3732jni HelloWorld实例 1.编写一个HelloWo ... -
vim 添加中文文档帮助
2012-04-07 18:38 2240(整理于网络) vim中文文档的主页是: http://vi ... -
Failure [INSTALL_FAILED_OLDER_SDK]
2012-04-07 15:11 148551.安装文件与运行环境的skd不匹配 打开源码目录下的And ... -
ubuntu wine 安装source insight
2012-03-04 20:33 46701 sudo apt-get install wine 下载s ... -
yaffs文件打包解包工具
2012-03-03 18:35 13484Yaffs(Yet Another Flash File Sy ... -
android 模态与非模态对话框实现
2012-02-29 23:31 196761.模态对话框是指对话框不消失,不能对其他页面进行操作,也就是 ... -
链接手机设备安装apk或其他操作no permission解决方法
2012-02-26 21:11 1290如题 依次执行以下命令 sudo su adb kil ... -
java source Attacher 1.2
2012-02-26 21:00 1273转自 http://www.oschina.net/news ... -
android intent命名规范
2011-12-10 23:39 1292ACTION_MAIN android:name=&quo ... -
touch mode
2011-12-10 23:34 1719touch mode 是用户在交互过程中的一种视图模式。当用户 ... -
获取当前task的topactivity
2011-09-22 19:10 4537获取当前task的activity方法 ActivityM ... -
android intent 常用用法
2011-08-22 22:45 936转自 http://www.cnblogs.com/lil ... -
Android.mk 基础
2011-08-22 22:43 1056(转自 http://www.cnblogs.com/lila ... -
设置android编码格式与包的引入格式于源码一致
2011-07-17 20:44 2110andorid源码编码格式以及引入包规则 在源码根目录---d ... -
关于设置activity样式
2011-07-08 16:09 2439在android中设置activity的样式时有两种方法 1. ... -
ubuntu apk反编译
2011-07-05 10:41 1492ubuntu系统下反编译apk 1. 下载dex2jar 并 ... -
IMSI , MCC MNC 的概念
2011-07-01 11:16 9866TelephonyManager telManager ...
相关推荐
Android Animation的简单Demo 相应博客地址:http://blog.csdn.net/u011268102/article/details/9707071
Android Animation动画资源文件
Android Animation学习笔记
android Animation动画实现loading效果
Android Animation动画Demo源码.rar
Androidanimation.docAndroidanimation.docAndroidanimation.docAndroidanimation.docAndroidanimation.doc
一本关于Android Animation开发的教程,详细的讲解了各种动画效果,并且拥有丰富的示例,能够让读者很快的领略到Animation的精华。
Android animation图片移动效果.rar
Android animation图片移动效果.zip源码资源下载Android animation图片移动效果.zip源码资源下载
Android animation图片移动效果.zip
Androidanimation图片移动效果.zip
Android animation图片移动效果.zip项目安卓应用源码下载Android animation图片移动效果.zip项目安卓应用源码下载 1.适合学生毕业设计研究参考 2.适合个人学习研究参考 3.适合公司开发项目技术参考
android animation 动画使用demo
对android animation重写,实现效果,blog 讲解地址:http://blog.csdn.net/luinsist/article/details/8164046
Android tween animation
Android animation的基本特性使用实例和两个大的实例:卫星菜单和闪亮文字。 文档地址:http://blog.csdn.net/sinat_30276961/article/details/49868409
上次提供了Animation动画其一Tween补间动画的源代码,这次提供其二Frame动画的源代码(以直接编码的形式实现Frame动画的Demo,笔者资源中另有以xml形式实现的Demo)。
使用Android原生Animation
View Animation Only animate View objects If animate non-view objects, you have to implement your own code takes less time to setup and requires less code to write Drawable Animation Load drawable ...