Android:关于Animation的几种常见的动画
来源:互联网 发布:临床试验数据核查 编辑:程序博客网 时间:2024/05/17 08:28
适当的添加一些动画效果,能够获得更好的用户体验,这次讲讲一些常见的动画~
如:透明动画,渐变动画等等。
先看一下运行截图:
附上代码,注释写在代码中:
MainActivity.java:
package com.vrinux.animotiondemo;import android.app.Activity;import android.os.Bundle;import android.view.View;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.ImageView;public class MainActivity extends Activity { private ImageView imgObj; private Animation animation; private AnimationSet animationSet; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); imgObj = (ImageView) findViewById(R.id.imgid); } public void animationshow(View view) { switch (view.getId()) { case R.id.btn01id: /** * 透明动画: AlphaAnimation(float fromAlpha,//变化起始状态的Alpha值; float * toAlpha)//变化结束状态的Alpha值; */ animation = new AlphaAnimation(0.0f, 1.0f); // 设置动画时长; animation.setDuration(3000); // 为组件添加动画; imgObj.setAnimation(animation); break; case R.id.btn02id: /** * 渐变动画: ScaleAnimation(float fromX, //变化起始状态x轴(即宽度)占控件的x轴(即宽度)的比例, * 1.0f为控件的宽度,0.0f表示没有宽度, 大于1.0f标识控件宽度的相应倍数; float * toX,//变化结束状态x轴(即宽度)占控件的x轴(即宽度)的比例; float fromY, * //变化起始状态y轴(即高度)占控件的y轴(即高度)的比例,和fromX同理; float toY, * //变化结束状态y轴(即高度)占控件的y轴(即高度)的比例; float pivotX,//变化的原点x轴坐标; float * pivotY)//变化的原点y轴坐标; */ animation = new ScaleAnimation(0.5f, 2.0f, 0.5f, 2.0f, 50.0f, 50.0f); animation.setDuration(3000); imgObj.setAnimation(animation); break; case R.id.btn03id: /** * 位移动画: TranslateAnimation(float fromXDelta, //位移起始x轴位置; float * toXDelta, //位移结束x轴位置; float fromYDelta, //位移起始y轴位置; float * toYDelta)//位移结束y轴位置; */ animation = new TranslateAnimation(0.0f, 100.0f, 0.0f, 100.0f); animation.setDuration(3000); imgObj.setAnimation(animation); break; case R.id.btn04id: /** * 旋转动画: RotateAnimation(float fromDegrees,//起始旋转度数; float * toDegrees, //结束旋转度数; float pivotX, //旋转原点的x轴坐标; float * pivotY)//旋转原点的y轴坐标; */ animation = new RotateAnimation(0.0f, 360.0f, 50.0f, 50.0f); animation.setDuration(3000); imgObj.setAnimation(animation); break; case R.id.btn05id: /** * AnimationSet(true)//动画集合(组合);顾名思义; */ AlphaAnimation animation1 = new AlphaAnimation(0.0f, 1.0f); ScaleAnimation animation2 = new ScaleAnimation(0.5f, 2.0f, 0.5f, 2.0f, 50.0f, 50.0f); TranslateAnimation animation3 = new TranslateAnimation(0.0f, 100.0f, 0.0f, 100.0f); RotateAnimation animation4 = new RotateAnimation(0.0f, 360.0f, 50.0f, 50.0f); animationSet = new AnimationSet(true); animationSet.addAnimation(animation1); animationSet.addAnimation(animation2); animationSet.addAnimation(animation3); animationSet.addAnimation(animation4); animationSet.setDuration(4000); imgObj.setAnimation(animationSet); break; } }}
activity_main.xml:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <ImageView android:id="@+id/imgid" android:layout_width="200dp" android:layout_height="200dp" android:layout_weight="1" android:src="@drawable/img" /> <Button android:id="@+id/btn01id" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_weight="1" android:onClick="animationshow" android:text="透明动画" android:textSize="20sp" /> <Button android:id="@+id/btn02id" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_weight="1" android:onClick="animationshow" android:text="渐变动画" android:textSize="20sp" /> <Button android:id="@+id/btn03id" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_weight="1" android:onClick="animationshow" android:text="位移动画" android:textSize="20sp" /> <Button android:id="@+id/btn04id" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_weight="1" android:onClick="animationshow" android:text="旋转动画" android:textSize="20sp" /> <Button android:id="@+id/btn05id" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_weight="1" android:onClick="animationshow" android:text="动画组合" android:textSize="20sp" /></LinearLayout>
图片资源:
img.jpg:
0 1
- Android:关于Animation的几种常见的动画
- Android 的几种Animation
- 几种常见的动画
- Android的animation(动画)
- Android的animation动画
- android开发中常见的几种动画
- Android的animation的四种动画
- Android animation 动画背景图自动播放的实现 几种方式
- 关于Android提供的Animation动画的实现
- 关于Android提供的Animation动画Java语言的实现
- 关于android动画animation
- Android中关于Animation和Animator动画的知识点总结
- Android的Animation动画相继
- Android动画的实现Animation
- android的动画效果Animation
- 关于Android动画的监听,开始,结束的控制分别有 Animation 动画和 ObjectAnimator 动画
- 关于android几种常见的UI综合
- 关于android studio几种常见的错误解决
- java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderListener
- Windows平台搭建Android分析环境
- POJ 3358- Period of an Infinite Binary Expansion(欧拉函数+欧拉定理)
- 给定数轴上n个点,找出一个到他们的距离之和尽量小的点
- P67 6
- Android:关于Animation的几种常见的动画
- Spring:三种实例化bean的方式
- 用了一下TI的检测三极/四极耳机的芯片TS3A227E,还挺好玩的
- php将文件类型session写入memcache
- 关于计算机视觉研究
- GitHub详细教程
- apache vhost配置
- find -mtime n
- 黑马程序员——java基础——String类和IO