Android学习篇章18-动画:Tween动画Animation
2013-11-01 17:24
288 查看
public class MyAnimation extends Animation{ float px=0; float py=0; float scale=1.5f; Camera cam=null; //在动画的播放过程中每一个阶段时间点都会调用这个方法 //interpolatedTime用来告诉我们动画已经播放了多少 取值在0-1之间 @Override protected void applyTransformation(float interpolatedTime, Transformation t) { //获得目前动画的变换矩阵 Matrix m= t.getMatrix(); cam.save(); cam.translate(0, 0, 1300-interpolatedTime*1300); cam.rotateY(720*interpolatedTime); // cam.rotateX(720*interpolatedTime); cam.getMatrix(m); m.preTranslate(-px, -py); m.postTranslate(px,py); cam.restore(); // m.setScale(interpolatedTime*scale, interpolatedTime*scale // ,px,py); // m.postRotate(720*interpolatedTime, px, py); } @Override public void initialize(int width, int height, int parentWidth, int parentHeight) { px=parentWidth/2; py=parentHeight/2; // TODO Auto-generated method stub super.initialize(width, height, parentWidth, parentHeight); this.setDuration(2500); this.setFillAfter(false); cam=new Camera(); //设置差值器为加速度差值器 this.setInterpolator(new AccelerateInterpolator()); } }
public class MainActivity extends Activity { ListView list1=null; ImageView img1=null; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); img1=(ImageView)findViewById(R.id.img1); // list1=(ListView)findViewById(R.id.list1); // String[] week={"星期天","星期一","星期二","星期三","星期四","星期五","星期六","星期六","星期六","星期六","星期六","星期六","星期六","星期六"}; // ArrayAdapter<String> adapter=new ArrayAdapter<String>(this,android.R.layout.simple_list_item_multiple_choice,week); // list1.setAdapter(adapter); } public void clickBtn(View view) { MyAnimation anim=new MyAnimation(); img1.startAnimation(anim); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; } }
mainxml:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" tools:context=".MainActivity" > <Button android:layout_width="match_parent" android:layout_height="wrap_content" android:onClick="clickBtn" android:text="播放" /> <ImageView android:id="@+id/img1" android:layout_width="match_parent" android:layout_height="match_parent" android:scaleType="fitXY" android:src="@drawable/s2" /> </LinearLayout>
anim_ctr.xml
<?xml version="1.0" encoding="utf-8"?> <layoutAnimation xmlns:android="http://schemas.android.com/apk/res/android" android:delay="30%" android:animationOrder="reverse" android:animation="@anim/rotate" />
rotate.xml
<?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android"> <rotate android:fromDegrees="0" android:toDegrees="720" android:pivotX="50%" android:pivotY="50%" android:duration="3000" /> </set>
scale.xml
<?xml version="1.0" encoding="utf-8"?> <scale xmlns:android="http://schemas.android.com/apk/res/android" android:interpolator="@android:anim/linear_interpolator" android:fromXScale="0" android:fromYScale="0" android:toYScale="1.5" android:toXScale="1.5" android:duration="3000" android:pivotX="50%" android:pivotY="50%" android:repeatCount="2" android:repeatMode="reverse" />
set_alpha_rotate.xml
<?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android"> <translate android:fromYDelta="-100%" android:toYDelta="0" android:duration="3000" /> <alpha android:fromAlpha="0" android:toAlpha="1.0" android:duration="3000"/> </set>
相关文章推荐
- Android游戏开发学习笔记(一):tweened animation自定义动画的实现
- Android学习篇章19-动画:Tween动画
- Android学习篇章17-动画1Frame动画AnimationDrawable
- Android(java)学习笔记199:Android中View动画(Tween Animation)
- Android补间动画(View Animation,Tweened Animation)
- Android动画学习笔记-Android Animation
- Android Animation学习笔记 Posted on 2010-01-11 23:00 feisky 阅读(40227) 评论(12) 编辑 收藏 关于动画的实现,Android提供了A
- Android动画之ViewAnimation(TweenAnimation)视图动画(补间动画)
- Android 动画--补间动画(Tween Animation)
- (4.1.23.0)Android Animation学习笔记及位移动画的P属性图示
- Android动画学习笔记-Android Animation
- Android 动画 Tweened Animation 之 RotateAnimation
- Android开发之动画(Animation)——Tween动画
- 【Android2D游戏开发十四】(未完待续)手把手教你在SurfaceView中照样使用Android 动画—Tween Animation!
- Android动画学习笔记-Android Animation
- Android Tween动画之RotateAnimation实现图片不停旋转效果实例介绍
- Android Tween动画之RotateAnimation实现图片不停旋转
- Android动画学习笔记-Android Animation
- Android 学习之补间(Tween)动画
- Android Animation学习 实现 IOS 滤镜退出动画