- 浏览: 151114 次
- 性别:
- 来自: 五指山
文章分类
最新评论
-
dengdonglin888:
qq_30221445 写道你好 请问这种数据能解吗 < ...
Simple XML -
qq_30221445:
你好 请问这种数据能解吗 <request> ...
Simple XML -
画个逗号给明天qu:
画个逗号给明天qu 写道
Android上传文件到服务器 -
画个逗号给明天qu:
...
Android上传文件到服务器 -
alranger:
我在jsp页面加上这一段代码后,问题还是存在。
解决Ext在ie9报错:不支持extjs对象的“createContextualFragment属性或方法”
转载自:http://www.pocketdigi.com/20110511/277.html
2011.10.28注:如果需要控件停在动画后的位置,需要设置android:fillAfter属性为true,在set节点中。默认在动画结束后回到动画前位置。设置android:fillAfter后,我们看到了控件留在了动画后的位置,其实也只是看到在那个位置,真实位置还是在原来动画前那里,你会发现Button不能被点击,就是这个原因。所以我们可以在动画结束后,手动把控件移动到动画结束后的位置。这就需要根结点为AbsoluteLayout,因为LinearLayout不能通过x,y座标定位。具体方法:把布局换成AbsoluteLayout,使用Animation的setAnimationListener设置动画播放事件,在onAnimationEnd方法中,使用控件的setLayoutParams方法,设置动画后的位置。
5月15日注:overridePendingTransition只支持android 2.0以上版本
Android的动画效果分为两种,一种是tweened animation(补间动画),第二种是frame by frame animation。一般我们用的是第一种。补间动画又分为AlphaAnimation,透明度转换 RotateAnimation,旋转转换 ScaleAnimation,缩放转换 TranslateAnimation 位置转换(移动)。
动画效果在anim目录下的xml文件中定义,在程序中用AnimationUtils.loadAnimation(Context context,int ResourcesId)载入成Animation对象,在需要显示动画效果时,执行需要动画的View的startAnimation方法,传入Animation,即可。切换Activity也可以应用动画效果,在startActivity方法后,执行overridePendingTransition方法,两个参数分别是切换前的动画效果,切换后的动画效果,下面的例子中传入的是两个alpha动画,以实现切换Activity时淡出淡入,渐隐渐现效果。
下面贴出代码:
两个Activity的布局文件 main.xml:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" android:id="@+id/ll" android:background="@drawable/white" > <TextView android:id="@+id/tv" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="translate动画效果" /> <TextView android:id="@+id/tv2" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="scale动画效果" /> <TextView android:id="@+id/tv3" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="alpha动画效果" /> <TextView android:id="@+id/tv4" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="rotate动画效果" /> <Button android:id="@+id/bt3" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="动画演示" /> <Button android:id="@+id/bt" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="切换" /> </LinearLayout> |
activity2.xml:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" android:id="@+id/ll2" > <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="Activity2" /> <Button android:id="@+id/bt2" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="返回main" /> </LinearLayout> |
动画效果XML文件,全部存放在anim目录下:
a1.xml 淡出效果
1 2 3 4 5 6 7 8 9 10 11 12 13 |
<?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android"> <alpha android:fromAlpha="1.0" android:toAlpha="0.0" android:duration="500" /> </set> <!-- fromAlpha:开始时透明度 toAlpha:结束时透明度 duration:动画持续时间 --> |
a2.xml 淡入效果:
1 2 3 4 5 6 7 8 |
<?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android"> <alpha android:fromAlpha="0.0" android:toAlpha="1.0" android:duration="500" /> </set> |
rotate.xml 旋转效果:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
<?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android"> <rotate android:interpolator="@android:anim/accelerate_decelerate_interpolator" android:fromDegrees="300" android:toDegrees="-360" android:pivotX="10%" android:pivotY="100%" android:duration="10000" /> </set> <!-- fromDegrees开始时的角度 toDegrees动画结束时角度 pivotX,pivotY不太清楚,看效果应该是定义旋转的圆心的 --> |
scale.xml 缩放效果:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
<?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android"> <scale android:interpolator= "@android:anim/decelerate_interpolator" android:fromXScale="0.0" android:toXScale="1.5" android:fromYScale="0.0" android:toYScale="1.5" android:pivotX="50%" android:pivotY="50%" android:startOffset="0" android:duration="10000" android:repeatCount="1" android:repeatMode="reverse" /> </set> <!-- interpolator指定动画插入器,常见的有加速减速插入器accelerate_decelerate_interpolator,加速插入器accelerate_interpolator,减速插入器decelerate_interpolator。 fromXScale,fromYScale,动画开始前X,Y的缩放,0.0为不显示,1.0为正常大小 toXScale,toYScale,动画最终缩放的倍数,1.0为正常大小,大于1.0放大 pivotX,pivotY动画起始位置,相对于屏幕的百分比,两个都为50%表示动画从屏幕中间开始 startOffset,动画多次执行的间隔时间,如果只执行一次,执行前会暂停这段时间,单位毫秒 duration,一次动画效果消耗的时间,单位毫秒,值越小动画速度越快 repeatCount,动画重复的计数,动画将会执行该值+1次 repeatMode,动画重复的模式,reverse为反向,当第偶次执行时,动画方向会相反。restart为重新执行,方向不变 --> |
translate.xml 移动效果:
1 2 3 4 5 6 7 8 9 10 11 12 13 |
<?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android"> <translate android:fromXDelta="320" android:toXDelta="0" android:fromYDelta="480" android:toYDelta="0" android:duration="10000" /> </set> <!-- fromXDelta,fromYDelta起始时X,Y座标,屏幕右下角的座标是X:320,Y:480 toXDelta,toYDelta动画结束时X,Y的座标 --> |
下面是程序代码,main.java:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
package com.pocketdigi.animation; import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.view.animation.Animation; import android.view.animation.AnimationUtils; import android.widget.Button; import android.widget.TextView; public class main extends Activity { /** Called when the activity is first created. */ TextView tv,tv2,tv3,tv4; Button bt3; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); Button bt=(Button)findViewById(R.id.bt); tv=(TextView)findViewById(R.id.tv); tv2=(TextView)findViewById(R.id.tv2); tv3=(TextView)findViewById(R.id.tv3); tv4=(TextView)findViewById(R.id.tv4); bt3=(Button)findViewById(R.id.bt3); bt.setOnClickListener(new OnClickListener(){ @Override public void onClick(View v) { // TODO Auto-generated method stub Intent intent=new Intent(main.this,activity2.class); startActivity(intent); overridePendingTransition(R.anim.a2,R.anim.a1); //淡出淡入动画效果 } }); bt3.setOnClickListener(new OnClickListener(){ @Override public void onClick(View v) { // TODO Auto-generated method stub Animation translate=AnimationUtils.loadAnimation(main.this, R.anim.translate); Animation scale=AnimationUtils.loadAnimation(main.this, R.anim.scale); Animation rotate=AnimationUtils.loadAnimation(main.this, R.anim.rotate); Animation alpha=AnimationUtils.loadAnimation(main.this, R.anim.a1); //载入XML文件成Animation对象 tv.startAnimation(translate); tv2.startAnimation(scale); tv3.startAnimation(alpha); tv4.startAnimation(rotate); //应用动画 }}); } } |
activity2.java:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
package com.pocketdigi.animation; import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; public class activity2 extends Activity { Button bt2; public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity2); bt2=(Button)findViewById(R.id.bt2); bt2.setOnClickListener(new OnClickListener(){ @Override public void onClick(View v) { // TODO Auto-generated method stub Intent intent=new Intent(activity2.this,main.class); startActivity(intent); overridePendingTransition(R.anim.a2,R.anim.a1); } }); } } |
注:动画切换Activity只有在新启动Activity才有效,如果Activity已经启动,并且intent加了FLAG_ACTIVITY_REORDER_TO_FRONT,这样不会新启动Activity,也就没有动画效果。
因为代码比较多,最后附上打包的源文件:
animation (671)
© 2011, 冰冻鱼. 请尊重作者劳动成果,复制转载保留本站链接! 应用开发笔记
发表评论
-
xUtils简介
2014-11-25 10:04 855xUtils 包含了很多实用的android工具。 xU ... -
直接拿来用!最火的Android开源项目
2014-07-25 11:01 704转 http://www.admin10000.com/d ... -
Android APK反编译详解(附图)
2014-03-28 10:56 828http://blog.csdn.net/ithomer/ar ... -
小米人
2014-02-17 17:23 689http://www.xiaomiren.net/ -
android开发之gallery 兑现滚动一张且短距离滑动实现滚动
2013-07-02 15:28 669http://www.myexception.cn/andro ... -
TextView显示插入的图片
2013-07-01 11:29 712http://orgcent.com/android-text ... -
TextView使用SpannableString设置复合文本
2013-07-01 11:29 653http://orgcent.com/android-text ... -
转:::Android TextView文字横向自动滚动(跑马灯)
2013-06-17 11:45 1519TextView实现文字滚动需要以下几个要点: 1.文字长度长 ... -
相片滤镜开源
2013-04-27 15:01 748https://github.com/daizhenjun/I ... -
android图片特效处理之模糊效果
2013-04-27 14:57 834http://blog.csdn.net/sjf0115/ar ... -
android图片处理方法(不断收集中)
2013-04-27 14:57 564http://gundumw100.iteye.com/blo ... -
Android, WindowsPhone7, IOS ,vc2010平台40多套图片滤镜开源
2013-04-27 14:56 677http://www.cnblogs.com/daizhj/a ... -
移动云存储平台
2013-04-25 16:13 911http://bmob.cn 关于Bmob 对于很多 ... -
android ExpandableListView简单应用及listview模拟ExpandableListView
2013-02-28 11:45 699http://blog.csdn.net/jj120522/a ... -
android_App集成支付宝
2013-02-28 11:43 798http://www.cnblogs.com/qianxude ... -
Android Pull Refresh View 插件
2012-12-01 12:43 856Android Pull Refresh View htt ... -
Android-TelephoneManager(转载)
2012-10-09 22:08 1355好文章齐分享。原文地址:http://blog.si ... -
android 开源 listview separato
2012-08-27 22:51 670http://code.google.com/p/androi ... -
fragment开源项目 学习
2012-08-13 12:02 933https://github.com/tisa007/Andr ... -
Fragment学习
2012-08-13 11:53 676http://www.eoeandroid.com/threa ...
相关推荐
Android动画效果 translate、scale、alpha、rotate 切换Activity动画 控件位置调整.zipAndroid动画效果 translate、scale、alpha、rotate 切换Activity动画 控件位置调整.zip 1.适合学生毕业设计研究参考 2.适合个人...
动画效果 translate、scale、alpha、rotate 切换Activity动画 控件位置调整
Android应用源码之动画效果 translate、scale、alpha、rotate 切换Activity动画 控件位置调Android应用源码之动画效果 translate、scale、alpha、rotate 切换Activity动画 控件位置调 1.适合学生毕业设计研究参考 2....
安卓Android源码——动画效果 translate、scale、alpha、rotate 切换Activity动画 控件位置调整.zip
安卓Android源码——动画效果translate、scale、alpha、rotate切换Activity动画控件位置调整.zip
Android translate动画、scale动画、alpha动画、rotate切换动画和Activity动画效果实例,包括了切换Activity时淡出淡入,渐隐渐现效果,还有控件位置调整实例源码,注:动画切换Activity只有在新启动Activity才有效...
免责声明:资料部分来源于合法的互联网渠道收集和整理,部分自己学习积累成果,供大家学习参考与交流。收取的费用仅用于收集和整理资料耗费时间的酬劳。 本人尊重原创作者或出版方,资料版权归原作者或出版方所有,...
源码参考,欢迎下载
安卓Android源码——动画效果 translate、scale、alpha、rotate 切换Activity动画 控件位置调整.zip
android activity切换动画效果大全,包括六个经典例子: 1、25个activity切换的动画效果; 2、android activity 切换效果库(劲推荐)...6、动画效果 translate、scale、alpha、rotate 切换Activity动画 控件位置调整;
动画效果 translate、scale、alpha、rotate 切换Activity动画 控件位置调整.zip 北京公交线路查询(离线).rar 基于socket通讯的文件续传!.rar 基于股票的一个Android应用(内含源码) .rar 多点缩放字体DEMO .rar ...
11. 动画:Android 中有两种动画:Tween 动画(alpha、scale、translate 和 rotate)和帧动画。熟悉动画可以帮助开发者更好地设计应用程序的界面。 12. Fragment:Android 中可以使用 Fragment 实现界面的切换,...
9.3.3 Translate动画 9.3.4 Rotate动画 9.4 Frame Animation 9.5 动画组件——ViewAnimator 9.5.1 ViewSwitcher 9.5.2 ViewFlipper 9.6 动画组件——PopupWindow 9.7 自定义View 9.8 控件扩展(表格) 9.8.1 设计...
6.1.4、位置转移动画效果 translate 163 6.1.5、四种动画效果的调用 164 7、异步调用 167 开辟一个线程: 167 THREAD: 168 HANDER 170 TIMER 173 ANDROID 界面刷新 174 MESSAGE HANDER 175 用法: 175 线程与子线程...
6.1.4、位置转移动画效果 translate 163 6.1.5、四种动画效果的调用 164 7、异步调用 167 开辟一个线程: 167 THREAD: 168 HANDER 170 TIMER 173 ANDROID 界面刷新 174 MESSAGE HANDER 175 用法: 175 线程与子线程...