zoukankan      html  css  js  c++  java
  • 帧动画



    准备8张图片名字分别为:loading1、loading2、loading3、loading4、

                         Loading5、loading6、loading7、loading8。

    在main.xml中:

    <LinearLayout

        android:id="@+id/group"

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

        android:layout_width="fill_parent"

        android:layout_height="fill_parent"

        android:background="#000000"

        android:orientation="vertical"

        android:gravity="center_horizontal">

      <ImageView

          android:id="@+id/loading"

          android:layout_marginTop="18dp"

          android:layout_width="wrap_content"

          android:layout_height="wrap_content"/>

      <Button

          android:id="@+id/start"

          android:layout_width="100dp"

          android:layout_height="40dp"

          android:layout_marginTop="30dp"

          android:background="#3399ff"

          android:textColor="#ffffff"

          android:text="开始动画"/>

    </LinearLayout>

    在res/anim下新建allloading.xml:

    <?xml version="1.0" encoding="utf-8"?>

    <animation-list

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

      android:oneshot="true">

      <item android:drawable="@drawable/loading1" android:duration="200" />

      <item android:drawable="@drawable/loading2" android:duration="200" />

      <item android:drawable="@drawable/loading3" android:duration="200" />

      <item android:drawable="@drawable/loading4" android:duration="200" />

      <item android:drawable="@drawable/loading5" android:duration="200" />

      <item android:drawable="@drawable/loading6" android:duration="200" />

      <item android:drawable="@drawable/loading7" android:duration="200" />

      <item android:drawable="@drawable/loading8" android:duration="200" />

    </animation-list>

    在MyAnimationDemo.java中:

    package com.li.animation;

    import android.annotation.SuppressLint;

    import android.app.Activity;

    import android.graphics.drawable.AnimationDrawable;

    import android.os.Bundle;

    import android.view.View;

    import android.view.View.OnClickListener;

    import android.view.animation.Animation;

    import android.view.animation.AnimationUtils;

    import android.widget.Button;

    import android.widget.ImageView;

    @SuppressLint({ "ParserError", "ParserError" })

    public class MyAnimationDemo extends Activity {

      private ImageView loading = null;

      private Button start = null;

      private AnimationDrawable draw = null;

        @Override

        public void onCreate(Bundle savedInstanceState) {

            super.onCreate(savedInstanceState);

            super.setContentView(R.layout.main);

            this.loading = (ImageView)super.findViewById(R.id.loading);

            this.start = (Button)super.findViewById(R.id.start);

            this.start.setOnClickListener(new OnClickListenerImpl());

        }

        private class OnClickListenerImpl implements OnClickListener{

         public void onClick(View v) {

           MyAnimationDemo.this.loading.setBackgroundResource(R.anim.allloading);

           MyAnimationDemo.this.draw = (AnimationDrawable)MyAnimationDemo

                .this.loading.getBackground();

           MyAnimationDemo.this.draw.setOneShot(false); //一直动

           MyAnimationDemo.this.draw.start();

         }

        }

    }

  • 相关阅读:
    链接服务器 "(null)" 的 OLE DB 访问接口 "Microsoft.Ace.OleDb.12.0" 报错。提供程序未给出有关错误的任何信息。
    iis应用程序池 内存溢出错误 System.OutOfMemoryException
    高性能JavaScript
    HTML5介绍
    Ubuntu 16.04安装Matlab 2016b教程
    C Standard Library: 9 Signals: <signal.h>
    C Standard Library:4 Mathematical Functions: <math.h>
    C Standard Library: File Positioning Functions
    C Standard Library: Formatted Input
    C Standard Library: 2 Character Class Tests: <ctype.h>
  • 原文地址:https://www.cnblogs.com/riskyer/p/3318011.html
Copyright © 2011-2022 走看看