`

Android View.startAnimation()动画

 
阅读更多

1.

    	Animation animation = AnimationUtils.loadAnimation(this, R.anim.location_pop_anim);
    	tvIcon.startAnimation(animation);
 

2.从上到下

<set xmlns:android="http://schemas.android.com/apk/res/android">

    <translate

       android:fromYDelta="-480"

       android:toYDelta="0"

       android:duration="1000"/>

</set>

 

从左到右

<set xmlns:android="http://schemas.android.com/apk/res/android">

   <translate

       android:fromXDelta="0"

       android:toXDelta="320"

       android:duration="3000"/>

</set>

 

 

单位为“%”表示相对于自己旋转

没有单位表示相对父类旋转

 

注意:如果一边位移translate,一边旋转rotate

在旋转的时候会按一个圆形不断减小的圆旋转。因为translate的时候,y不断的变化,rotate会根据这个y值不断变化而变化!

 

 

如果希望执行完一个后再执行另外一个效果,假设第一个效果执行时间是

 

android:duration="1000"

 在下一个效果中设置下面的代码,那么这个效果就可以在上一个效果执行完后再执行

 

  android:startOffset="1000"
 

 

希望设置某个效果重复执行的话

	android:repeatMode="restart"
	android:repeatCount="10"
 

 

 

注:Delta也可以用%p為單位 

例子:

android:fromXDelta="0" android:toXDelta="-100%p" 往左邊消失

android:fromXDelta="-100%p" android:toXDelta="0" 從左邊進

android:fromXDelta="0" android:toXDelta="100%p" 往右邊消失

android:fromXDelta="100%p" android:toXDelta="0" 從右邊進

 

 

二、Rotate 定義視圖旋轉角度

視圖的中心位置旋轉360度,時間1 秒完成

<set xmlns:android="http://schemas.android.com/apk/res/android">

<rotate 

    android:fromDegrees="0"

    android:toDegrees="+360"

    android:pivotX="50%"

    android:pivotY="50%"

    android:duration="1000"/>

</set>

三、Scale 定義視圖縮放動畫

<set xmlns:android="http://schemas.android.com/apk/res/android"  

        android:interpolator="@android:anim/accelerate_interpolator">  

   <scale android:fromXScale="0.0" android:toXScale="1.0"  

         android:fromYScale="0.0" android:toYScale="1.0"  

         android:pivotX="50%p" android:pivotY="50%p"  

         android:duration="300"/>  

</set> 
//上面的效果為從中間爆出來的效果,可用于Activity的過度效果

釋:Scale定義如何沿著x軸方向(或y軸方向)改變視圖的大小,視圖大小發生變化時樞軸(pivot)位置是保持不變的 pivotX/pivotY為x/y軸的百分比

四、Alpha 定義視圖的透明痛

<set xmlns:android="http://schemas.android.com/apk/res/android">

<alpha 

    android:fromAlpha="0.1"

    android:toAlpha="1.0"

    android:duration="3000"/>

</set>

    注:透明度變化范圍從0.0(透明)到1.0(不透明)

 

 

参考:http://blog.csdn.net/wfung_kwok/article/details/7202682

分享到:
评论
1 楼 蓝月儿 2012-12-13  
好详细那 谢谢啦

相关推荐

    安卓属性动画

    //使用ImageView的startAnimation方法执行动画 image1.startAnimation(animationSet); image2.startAnimation(animationSet); image3.startAnimation(animationSet); image4.startAnimation(animationSet); ...

    android图片旋转、淡入淡出、缩放效果、移动效果示例.rar

    android图片旋转、淡入淡出、缩放效果、移动效果示例,先来看下截图的运行效果,单击对应的按钮,即可看到效果,淡入淡出之类的,图片旋转之类的。  图片旋转的代码如下:  rotateAnimation.setDuration(5000);  ...

    Android SmoothTransition listview和gridview的item进入动画.zip

    Android SmoothTransition listview和gridview的item进入动画 ,每一个item可以自定义进入动画, 自定义SwitchAnimationUtil,当页面焦点变化的时候 onWindowFocusChanged(boolean hasFocus) 就 mSwitchAnimationUtil...

    Amin[2D动画(补间动画)]

    imageView.startAnimation(animation); //帧动画 //获取用于显示帧动画的控件 ImageView loadingView=(ImageView)findViewById(R.id.Image_loading_View); //将“帧动画”文件,加载至控件的背景 ...

    ios-一款简单好用的跑马灯效果-swift.zip

    drawMarqueeView.startAnimation() 3、暂停 drawMarqueeView.pauseAnimation() 4、恢复 drawMarqueeView.resumeAnimation() 5、停止 drawMarqueeView.stopAnimation() ****详见demo***********

    android顶部滑动导航

    &lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:background="#F0EFF5" &gt; android:id=...

    Android代码-Animated-Icons

    animatedIconView.startAnimation(); Installation Add this to your module build.gradle file: dependencies { ... compile "com.github.tarek360:Animated-Icons:1.2.0" } Add this to your root build.gradle...

    Java改变鼠标样式,动画光标.rar

    Java改变鼠标样式,动画光标,建立一个用于动画的图标数组,建立Timer对象,实例化动画图标,实例化窗口对象,增加组件到窗口上,设置窗口尺寸,设置窗口可视。。。鼠标不再是一个小箭头,而是一个会动的小宠物,在...

    Android SNS交友社区项目源码实例.rar

    Android SNS交友社区项目源码实例,比较大型的开源SNS交友方面的实例,对学习研究android APP开发有不小的帮助。  myAnimation= AnimationUtils.loadAnimation(this,R.anim.welcome);//加载动画  myImageView = ...

    ViewPagerFragment滑动切换

    import android.view.View; import android.view.ViewGroup; import android.view.animation.Animation; import android.view.animation.TranslateAnimation; import android.widget.ImageView; import android....

    浅析Android手机卫士之抖动输入框和手机震动

    查看apiDemos,找到View/Animation/shake找到对应的动画代码,直接拷贝过来 当导入一个项目的时候,报R文件不存在,很多情况是xml文件出错了 Animation shake = AnimationUtils.loadAnimation(this, R.anim.shake)...

    Android重写Gallery

    // 切换View动画 mAnimation = new FlingGalleryAnimation(); mGestureDetector = new GestureDetector(new FlingGestureDetector()); mDecelerateInterpolater = AnimationUtils.loadInterpolator(mContext...

    九宫格牌翻转游戏demo

    &lt;RelativeLayout 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" ...

    across:使用JavaScript工具CSS动画库

    使用: loading.startAnimation() 和 loading.stopAnimation();可以用于开启和关闭动画[removed][removed]var animations =new NewAcross({target:’id’,//id of div or otherstype:’type1’,//animation type ...

    任意方向滑动的scrollview 解决快速滑动内容消失的bug

    inner.startAnimation(ta); // 设置回到正常的布局位置 new Handler().postDelayed(new Runnable() { public void run() { /* * modify by taocungui for content disappear bug * @2014.9.17 */ if...

    Android代码-GifImageView

    Android ImageView that handles Animated GIF images Usage In your build.gradle file: dependencies { compile 'com.felipecsl:gifimageview:2.1.0' } In your Activity class: @Override protected void ...

    Android程序设计课程报告.doc

    ll.startAnimation(alphaAnimation); progressDialog = new ProgressDialog(this); progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL); progressDialog.setMessage("正在下载..."); new Thread() ...

    Rotate3dAnimation-基于谷歌官方提供的3D翻转示例进行修改,修复了在不同设备上显示效果差异过大的问题。.zip

    基于谷歌官方提供的3D翻转示例进行修改,修复了在不同设备上显示效果差异过大的问题。项目地址:https://github.com/GcsSloop/Rotate3dAnimation 效果图:如何使用://... view.startAnimation(rotation); //开始动画

    Java在窗口上加载显示GIF动画图像.rar

     public void startAnimation() { //开始动画   if (animationTimer==null) {   currentImage=0;   animationTimer=new Timer(delay, this); //实例化Timer对象   animationTimer.start(); //开始运行 ...

Global site tag (gtag.js) - Google Analytics