Q群: 241359063 更精彩,欢迎共同走向创业学习之旅。
原创:kylin_zeng http://blog.chinaunix.net/uid/23795897.html在此感谢mars 老师的帮助。转载请注明原创出处,尊重他人的劳动成果。
1、animations 提供一个动画的效果。
2、animation 分成两类:
第一类: Tweened Animations,提供旋转Rotate,移动Translate,伸展缩放Scale,淡入淡出Alpha.
第二类: Frame-by-Frame animation. 这类可以创建一个drawable 系列,可以按照指定时间间隔显示。
3、第一类详解:步骤:
3.1 创建一个AnimationSet 对象;
3.2 根据需要创建队友的Animation 对象;
3.3 根据软件动画的需要为Animation对象设置对应的数据。
3.4 将Animation 对象添加到AnimationSet 对象里面。
3.5 使用空间对象开始执行AnimationSet.
创建ImageView图片来查看效果:
<ImageView android:id="@+id/imageViewId"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_centerInParent="true" android:layout_marginTop="100dip"
android:src="@drawable/icon" />
1、创建几个按钮来控制:
2、
02_08.zip
阅读(34) | 评论(0) | 转发(0) |
<script>window._bd_share_config={"common":{"bdSnsKey":{},"bdText":"","bdMini":"2","bdMiniList":false,"bdPic":"","bdStyle":"0","bdSize":"16"},"share":{}};with(document)0[(getElementsByTagName('head')[0]||body).appendChild(createElement('script')).src='http://bdimg.share.baidu.com/static/api/js/share.js?v=89860593.js?cdnversion='+~(-new Date()/36e5)];</script>
原创:kylin_zeng http://blog.chinaunix.net/uid/23795897.html在此感谢mars 老师的帮助。转载请注明原创出处,尊重他人的劳动成果。
1、animations 提供一个动画的效果。
2、animation 分成两类:
第一类: Tweened Animations,提供旋转Rotate,移动Translate,伸展缩放Scale,淡入淡出Alpha.
第二类: Frame-by-Frame animation. 这类可以创建一个drawable 系列,可以按照指定时间间隔显示。
3、第一类详解:步骤:
3.1 创建一个AnimationSet 对象;
3.2 根据需要创建队友的Animation 对象;
3.3 根据软件动画的需要为Animation对象设置对应的数据。
3.4 将Animation 对象添加到AnimationSet 对象里面。
3.5 使用空间对象开始执行AnimationSet.
创建ImageView图片来查看效果:
<ImageView android:id="@+id/imageViewId"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_centerInParent="true" android:layout_marginTop="100dip"
android:src="@drawable/icon" />
1、创建几个按钮来控制:
点击(此处)折叠或打开
- <?xml version="1.0" encoding="utf-8"?>
- <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:orientation="vertical" android:layout_width="fill_parent"
- android:layout_height="fill_parent">
-
- <Button android:id="@+id/scaleButtonId" android:layout_width="fill_parent"
- android:layout_height="wrap_content" android:layout_alignParentBottom="true"
- android:text="测试scale动画效果" />
-
- <Button android:id="@+id/rotateButtonId" android:layout_width="fill_parent"
- android:layout_height="wrap_content" android:layout_above="@id/scaleButtonId"
- android:text="测试rotate动画效果" />
-
- <Button android:id="@+id/alphaButtonId" android:layout_width="fill_parent"
- android:layout_height="wrap_content" android:layout_above="@id/rotateButtonId"
- android:text="测试alpha动画效果" />
-
- <Button android:id="@+id/translateButtonId"
- android:layout_width="fill_parent" android:layout_height="wrap_content"
- android:layout_above="@id/alphaButtonId" android:text="测试translate动画效果" />
-
- <LinearLayout android:orientation="vertical"
- android:layout_width="fill_parent" android:layout_height="fill_parent">
-
- <ImageView android:id="@+id/imageViewId"
- android:layout_width="wrap_content" android:layout_height="wrap_content"
- android:layout_centerInParent="true" android:layout_marginTop="100dip"
- android:src="@drawable/icon" />
- </LinearLayout>
- </RelativeLayout>
2、
点击(此处)折叠或打开
- package mars.animations01;
-
- import android.app.Activity;
- import android.os.Bundle;
- import android.view.View;
- import android.view.View.OnClickListener;
- import android.view.animation.AlphaAnimation;
- import android.view.animation.Animation;
- import android.view.animation.AnimationSet;
- import android.view.animation.RotateAnimation;
- import android.view.animation.ScaleAnimation;
- import android.view.animation.TranslateAnimation;
- import android.widget.Button;
- import android.widget.ImageView;
-
- public class MainActivity extends Activity {
- /** Called when the activity is first created. */
- private ImageView imageView = null;
- private Button rotateButton = null;
- private Button scaleButton = null;
- private Button alphaButton = null;
- private Button translateButton = null;
-
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.main);
- imageView = (ImageView) findViewById(R.id.imageViewId);
-
- rotateButton = (Button) findViewById(R.id.rotateButtonId);
- rotateButton.setOnClickListener(new RotateButtonListener());
-
- scaleButton = (Button) findViewById(R.id.scaleButtonId);
- scaleButton.setOnClickListener(new ScaleButtonListener());
-
- alphaButton = (Button) findViewById(R.id.alphaButtonId);
- alphaButton.setOnClickListener(new AlphaButtonListener());
-
- translateButton = (Button) findViewById(R.id.translateButtonId);
- translateButton.setOnClickListener(new TranslateButtonListener());
- }
-
- private class RotateButtonListener implements OnClickListener {
-
- @Override
- public void onClick(View view) {
- AnimationSet animationSet = new AnimationSet(true);
- RotateAnimation rotateAnimation = new RotateAnimation(0, 360, /*从0旋转到360度*/
- Animation.RELATIVE_TO_PARENT, 1f, /*x轴以父控件为参照物,1f -> 从0~1,如果是0.5表示一半*/
- Animation.RELATIVE_TO_PARENT, 0f); /*y轴以父控件为参照物,0f -> 从0~1,如果是0.5表示一半*/
- rotateAnimation.setDuration(5000); //持续时间5000ms
- animationSet.addAnimation(rotateAnimation);
- imageView.startAnimation(animationSet);
- }
- }
-
- private class ScaleButtonListener implements OnClickListener {
-
- @Override
- public void onClick(View view) {
- AnimationSet animationSet = new AnimationSet(true);
- ScaleAnimation scaleAnimation = new ScaleAnimation(1, 0.1f, 1, 0.5f, /*1,0.1f, x轴从1到10%。 1,0.5f, y轴从1到0.5*/
- Animation.RELATIVE_TO_SELF, 0.5f,
- Animation.RELATIVE_TO_SELF, 0.5f);
- animationSet.addAnimation(scaleAnimation);
- animationSet.setStartOffset(1000);
- animationSet.setFillAfter(true);
- animationSet.setFillBefore(false);
- animationSet.setDuration(2000);
- imageView.startAnimation(animationSet);
- }
-
- }
-
- private class AlphaButtonListener implements OnClickListener {
-
- @Override
- public void onClick(View view) {
- //创建一个AnimationSet对象
- AnimationSet animationSet = new AnimationSet(true);
- //创建一个AlphaAnimation对象
- AlphaAnimation alphaAnimation = new AlphaAnimation(1, 0);
- //设置动画执行的时间(单位:毫秒)
- alphaAnimation.setDuration(1000);
- //将AlphaAnimation对象添加到AnimationSet当中
- animationSet.addAnimation(alphaAnimation);
- //使用ImageView的startAnimation方法开始执行动画
- imageView.startAnimation(animationSet);
- }
-
- }
-
- private class TranslateButtonListener implements OnClickListener {
-
- @Override
- public void onClick(View view) {
- AnimationSet animationSet = new AnimationSet(true);
- TranslateAnimation translateAnimation = new TranslateAnimation(
- Animation.RELATIVE_TO_SELF, 0f, /*x轴移动开始值*/
- Animation.RELATIVE_TO_SELF, 0.5f, /*x轴移动后的值*/
- Animation.RELATIVE_TO_SELF, 0f, /*y轴移动开始值*/
- Animation.RELATIVE_TO_SELF, 1.0f); /*y轴移动后的值*/
- translateAnimation.setDuration(1000);
- animationSet.addAnimation(translateAnimation);
- imageView.startAnimation(animationSet);
- }
- }
- }
02_08.zip
相关热门文章
给主人留下些什么吧!~~
评论热议