免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1316 | 回复: 1
打印 上一主题 下一主题

Android开发_Animation(2) [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2012-03-02 17:12 |只看该作者 |倒序浏览
Android开发_Animation(2)









新建项目:

http://www.cnblogs.com/hongten/gallery/image/112169.html

项目结构:

http://www.cnblogs.com/hongten/gallery/image/112168.html

main.xml
  1. 1 <?xml version="1.0" encoding="utf-8"?> 2 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 3     android:orientation="vertical" 4     android:layout_width="fill_parent" 5     android:layout_height="fill_parent" 6     > 7  8     <!-- translate移动位置 --> 9     <Button10         android:id="@+id/btn_translate"11         android:layout_width="fill_parent"12         android:layout_height="wrap_content"13         android:layout_alignParentBottom="true"14         android:text="测试translate移动动画效果"15     />16     <!-- alpha淡入淡出效果 -->17     <Button18         android:id="@+id/btn_alpha"19         android:layout_width="fill_parent"20         android:layout_height="wrap_content"21         android:layout_above="@id/btn_translate"22         android:text="测试alpha淡入/出效果"23     />24     <!-- rotate旋转效果 -->25     <Button26         android:id="@+id/btn_rotate"27         android:layout_width="fill_parent"28         android:layout_height="wrap_content"29         android:layout_above="@id/btn_alpha"30         android:text="测试rotate旋转效果"31     />32     <!-- scale伸缩效果 -->33     <Button34         android:id="@+id/btn_scale"35         android:layout_width="fill_parent"36         android:layout_height="wrap_content"37         android:layout_above="@id/btn_rotate"38         android:text="测试scale伸缩效果"39     />40     <LinearLayout41         android:orientation="vertical"42         android:layout_width="wrap_content"43         android:layout_height="wrap_content"44     >45     <!-- 存放测试图片 -->46         <ImageView 47         android:id="@+id/imageViewId"48         android:layout_width="wrap_content"49         android:layout_height="wrap_content"50         android:layout_centerInParent="true"51         android:layout_marginTop="100dip"52         android:src="@drawable/icon"53         />54     </LinearLayout>55 </RelativeLayout>复制代码
复制代码
anim/alpha.xml
  1. 1 <?xml version="1.0" encoding="utf-8"?> 2 <set xmlns:android="http://schemas.android.com/apk/res/android" 3     android:interpolator="@android:anim/accelerate_interpolator"> 4     <!-- 淡入淡出,从完全不透明变化到完全透明,持续时间为5秒 --> 5     <alpha 6         android:fromAlpha="1.0" 7         android:toAlpha="0.0" 8         android:startOffset="500" 9         android:duration="5000"10     />11 </set>复制代码anim/translate.xml
复制代码
  1. 1 <?xml version="1.0" encoding="utf-8"?> 2 <set xmlns:android="http://schemas.android.com/apk/res/android" 3     android:interpolator="@android:anim/accelerate_interpolator"> 4     <!-- 移动位置,持续时间为5秒 --> 5     <translate 6         android:fromXDelta="50%" 7         android:toXDelta="50%" 8         android:fromYDelta="0%" 9         android:toYDelta="100%"10         android:duration="5000"11     />12 </set>复制代码
复制代码
anim/scale.xml
  1. 1 <?xml version="1.0" encoding="utf-8"?> 2 <set xmlns:android="http://schemas.android.com/apk/res/android" 3     android:interpolator="@android:anim/accelerate_interpolator"> 4     <!-- 伸缩,从不可见状态变化到原本状态,持续时间为5秒 --> 5     <scale 6         android:fromXScale="0.0" 7         android:toXScale="1.0" 8         android:fromYScale="0.0" 9         android:toYScale="1.0"10         android:pivotX="50%"11         android:pivotY="50%"12         android:duration="5000"13     />14 </set>复制代码anim/rotate.xml

  2. 1 <?xml version="1.0" encoding="utf-8"?> 2 <set xmlns:android="http://schemas.android.com/apk/res/android" 3     android:interpolator="@android:anim/accelerate_interpolator"> 4     <!-- 旋转,根据自己的中心位置旋转,持续时间为5秒 --> 5     <rotate  6         android:fromDegrees="0"  7         android:toDegrees="+350" 8         android:pivotX="50%"  9         android:pivotY="50%" 10         android:duration="5000" />11 </set>复制代码
复制代码
MainActivity.java
  1. 1 package com.b510; 2  3 import android.app.Activity; 4 import android.os.Bundle; 5 import android.view.View; 6 import android.view.View.OnClickListener; 7 import android.view.animation.Animation; 8 import android.view.animation.AnimationUtils; 9 import android.widget.Button;10 import android.widget.ImageView;11 12 /**13  * 14  * @author Hongten15  * 16  */17 public class MainActivity extends Activity {18     /** 图片显示 */19     private ImageView imageView;20     /** 旋转 */21     private Button rotate;22     /** 淡入淡出 */23     private Button alpha;24     /** 伸缩 */25     private Button scale;26     /** 移动位置 */27     private Button translate;28 29     /** Called when the activity is first created. */30     @Override31     public void onCreate(Bundle savedInstanceState) {32         super.onCreate(savedInstanceState);33         setContentView(R.layout.main);34 35         imageView = (ImageView) findViewById(R.id.imageViewId);36 37         rotate = (Button) findViewById(R.id.btn_rotate);38         alpha = (Button) findViewById(R.id.btn_alpha);39         scale = (Button) findViewById(R.id.btn_scale);40         translate = (Button) findViewById(R.id.btn_translate);41 42         rotate.setOnClickListener(new OnClickListener() {43             @Override44             public void onClick(View v) {45                 // 使用AnimationUtils装载动画设置46                 Animation animation = AnimationUtils.loadAnimation(47                         MainActivity.this, R.anim.rotate);48                 // 使用imageView对象的startAnimation方法执行动画49                 imageView.startAnimation(animation);50             }51         });52         alpha.setOnClickListener(new OnClickListener() {53             @Override54             public void onClick(View v) {55                 // 使用AnimationUtils装载动画设置56                 Animation animation = AnimationUtils.loadAnimation(57                         MainActivity.this, R.anim.alpha);58                 // 使用imageView的startAnimation方法执行动画59                 imageView.startAnimation(animation);60             }61         });62         scale.setOnClickListener(new OnClickListener() {63             @Override64             public void onClick(View v) {65                 // 使用AnimationUtils装载动画设置66                 Animation animation = AnimationUtils.loadAnimation(67                         MainActivity.this, R.anim.scale);68                 // imageView对象调用startAnimation方法执行动画69                 imageView.startAnimation(animation);70             }71         });72         translate.setOnClickListener(new OnClickListener() {73             @Override74             public void onClick(View v) {75                 // 使用AnimationUtils装载动画设置76                 Animation animation = AnimationUtils.loadAnimation(77                         MainActivity.this, R.anim.translate);78                 // imageView对象调用startAnimation方法执行动画79                 imageView.startAnimation(animation);80             }81         });82     }83 }复制代码
复制代码
运行效果

1.初始化

http://www.cnblogs.com/hongten/gallery/image/112170.html

2.scale效果

http://www.cnblogs.com/hongten/gallery/image/112171.html

3.rotate效果

http://www.cnblogs.com/hongten/gallery/image/112172.html

4.alpha效果

http://www.cnblogs.com/hongten/gallery/image/112173.html

5.translate效果

http://www.cnblogs.com/hongten/gallery/image/112174.html

论坛徽章:
0
2 [报告]
发表于 2012-03-02 17:12 |只看该作者
谢谢分享
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP