首页 > 代码库 > android的ViewPager和Animation的一些使用(二)
android的ViewPager和Animation的一些使用(二)
Animation的部分
android的animation分为scale,rotate,tranlateAnimation,alpha这几种
start animation的方式以下几种:
<span style="white-space:pre"> </span> t1_icon1.setImageResource(R.drawable.t1_frame_animation); //<span style="font-family: Arial, Helvetica, sans-serif;">t1_frame_animation这个动画是放在drawable下的</span> t1_icon1_animationDrawable = (AnimationDrawable) t1_icon1 .getDrawable(); t1_icon1_animationDrawable.start();
t1_frame_animation的xml 是两种图案的交替显示: <?xml version="1.0" encoding="UTF-8"?> <animation-list android:oneshot="false" xmlns:android="http://schemas.android.com/apk/res/android"> <item android:duration="200" android:drawable="@drawable/tutorial1_icon1" /> <item android:duration="200" android:drawable="@drawable/tutorial1_icon2" /> </animation-list>
还有一种是放在anim文件夹下:
<span style="white-space:pre"> </span> Animation tutorail_rotate = AnimationUtils.loadAnimation(MainActivity.this, R.anim.tutorail_rotate); t1_icon2.startAnimation(tutorail_rotate);
<?xml version="1.0" encoding="UTF-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android"> <scale android:interpolator="@android:anim/accelerate_decelerate_interpolator" android:duration="800" android:pivotX="50.0%" android:pivotY="50.0%" android:fillAfter="false" android:fromXScale="0.0" android:toXScale="1.2" android:fromYScale="0.0" android:toYScale="1.2" /> <rotate android:duration="3000" android:fromDegrees="0.0" android:toDegrees="359.0" android:pivotX="50.0%" android:pivotY="50.0%" android:repeatCount="infinite" /> </set>
其中: pivotX为属性为动画相对于物件的X坐标的开始位置,一般填50%,就是View的中心点,repeateCount的意思是重复的次数
还有一种为LayoutAnimation:
直接在xml中加载
对于这样的引导页面:
第一页的动画是:
t1_icon1.setImageResource(R.drawable.t1_frame_animation); t1_icon1_animationDrawable = (AnimationDrawable) t1_icon1 .getDrawable(); t1_icon1_animationDrawable.start(); Animation tutorail_rotate = AnimationUtils.loadAnimation(MainActivity.this, R.anim.tutorail_rotate); t1_icon2.startAnimation(tutorail_rotate); Animation tutorail_scalate = AnimationUtils.loadAnimation(MainActivity.this, R.anim.tutorail_scalate); t1_fixed.startAnimation(tutorail_scalate); Animation tutorail_bottom = AnimationUtils.loadAnimation(MainActivity.this, R.anim.tutorail_bottom); t1_next.startAnimation(tutorail_bottom);
<pre name="code" class="java" style="line-height: 18px;">tutorail_scalate<span style="font-family: Consolas, 'Courier New', Courier, mono, serif;">为:</span>
<?xml version="1.0" encoding="UTF-8"?><set xmlns:android="http://schemas.android.com/apk/res/android"> <scale android:interpolator="@android:anim/accelerate_decelerate_interpolator" android:duration="1000" android:pivotX="50.0%" android:pivotY="50.0%" android:fillAfter="false" android:fromXScale="0.0" android:toXScale="1.1" android:fromYScale="0.0" android:toYScale="1.1" /></set>
<span style="font-family: Consolas, 'Courier New', Courier, mono, serif;">tutorail_bottom为:</span>
<pre name="code" class="java" style="line-height: 18px;"><pre name="code" class="html"><?xml version="1.0" encoding="UTF-8"?> <set android:repeatMode="reverse" xmlns:android="http://schemas.android.com/apk/res/android"> <translate android:duration="1000" android:repeatCount="infinite" android:fromXDelta="0.0" android:toXDelta="0.0" android:fromYDelta="-15.0" android:toYDelta="20.0" /> <alpha android:duration="1000" android:repeatCount="infinite" android:fromAlpha="1.0" android:toAlpha="0.3" /> </set>
第一页的Layout为:
<pre name="code" class="html"><?xml version="1.0" encoding="UTF-8"?> <LinearLayout android:gravity="center" android:orientation="vertical" android:background="@android:color/white" android:layout_width="fill_parent" android:layout_height="fill_parent" xmlns:android="http://schemas.android.com/apk/res/android"> <ImageView android:id="@+id/t1_fixed" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginBottom="15.0dip" android:src=http://www.mamicode.com/"@drawable/tutorial1_fixed" />>第4页的火箭是采用:<span style="white-space:pre"> </span>t3_icon6.setImageResource(R.drawable.t3_frame_animation);<span style="white-space:pre"> </span>AnimationDrawable t3_icon6_animationDrawable = (AnimationDrawable) t3_icon6.getDrawable();<span style="white-space:pre"> </span>t3_icon6_animationDrawable.start();<pre name="code" class="html" style="line-height: 18px;">t3_frame_animation为:<?xml version="1.0" encoding="UTF-8"?><animation-list android:oneshot="false" xmlns:android="http://schemas.android.com/apk/res/android"> <item android:duration="70" android:drawable="@drawable/rocket_long" /> <item android:duration="70" android:drawable="@drawable/rocket_middle" /> <item android:duration="70" android:drawable="@drawable/rocket_short" /></animation-list>第四页的摆动动画这样写:int pivot = Animation.RELATIVE_TO_SELF;<span style="white-space:pre"> </span>CycleInterpolator interpolator = new CycleInterpolator(3.0f);<span style="white-space:pre"> </span>RotateAnimation animation = new RotateAnimation(0, 10, pivot, 0.47f, pivot, 0.05f);<span style="white-space:pre"> </span>animation.setStartOffset(500);<span style="white-space:pre"> </span>animation.setDuration(3000);<span style="white-space:pre"> </span>animation.setRepeatCount(1);// Animation.INFINITE<span style="white-space:pre"> </span>animation.setInterpolator(interpolator);<span style="white-space:pre"> </span>t4_icon1.startAnimation(animation);
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。