Android的动画

3.0以前 ,Android只支持两种动画模式 即tweenAnimation动画和frameAnimation动画 、 在Android3.0中有引进了一个新的动画模式:propertyAnimation 

补间动画(TweenAnimation)支持动画的缩放、渐变、移动、翻转。帧动画(frameAnimation)是一种逐帧播放动画的模式、这两种模式都有简单的接口。

Animtation:动画抽象类

  其他一些动画实现类都继承了Animation类的方法、

方法之一:setDuration(2000)设置动画持续的时间 括号中的是毫秒

  

   Animation.setDuration(2000)

方法之二:startNow()   马上启动动画

方法之三:canle()  动画取消 



接下来、我们讲下TweenAnimation(补间动画)

补间动画有四种动画模式     1:ScaleAnimation(缩放动画)2:RotateAnimation(旋转动画)3:AlphaAnimation(透明度动画)4:平移动画(TranslateAnimation)

我们一个一个讲吧

ScaleAnimation(缩放动画):将View按一定的尺寸进行缩放或者扩大

      构造方法;  ScaleAnimation(float fromX,float toX,floatfromY,float toY);

       fromX:动画开始的X轴坐标    toX:动画结束的X轴坐标

       fromY:动画开始的Y轴坐标   toY:动画结束的Y轴坐标

例子:

main,xml文件

<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="${packageName}.${activityClass}" >
  <LinearLayout
      android:layout_width="fill_parent"
      android:layout_height="wrap_content"
      android:orientation="horizontal" >
      <Button
          android:id="@+id/button1"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:background="@drawable/button"
          android:text="start"
          android:onClick="start"/>
          
          <Button
          android:id="@+id/button2"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:background="@drawable/button"
          android:text="stop"
          android:onClick="stop"/>
           </LinearLayout>
    <ImageView 
        android:id="@+id/image"
        android:layout_gravity="center_horizontal"
        android:layout_width="200dp"
        android:layout_height="200dp"
        android:src="@drawable/chrome"/>




</LinearLayout>

public class MyAnimation implements OnClickListener{

              /**

             *当start按钮被单击时、动画开始、当stop按钮被单击时、动画结束

            *

             */

       private ImageView image;

       private ScaleAnimation scale;

        

       public void onCreate(Boundle savedInstanceState){

               super( savedInstanceState);

                setContentView(R.layout.main);  //加载布局文件

                image = (ImageView)findViewById(R.id.image);  //通过Id获取组件

                scale = new ScaleAnimation(0,200,0,200);    //设置动画

                }

        public void start(View e){

              scale.setDuration(4000);   //设置动画持续时间为4秒

               image.startAnimation(scale);  //ImageView启动动画

              }

          public void stop(View e){

                   scale.cancle();   //动画取消

            }

        public void onClick(View e){
         }

}

  好了,我就只写到这了、其他的动画、大家可以网上搜索到的。

           









评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值