• Loading Image


    Android doesn’t handle animated gifs, but here’s one way to display an animated loading image that is similar to the Spinner style of ProgressDialog.

     

    Image Files:

    Loading Images

    drawable/loading.xml

    <animation-list xmlns:android="http://schemas.android.com/apk/res/android"
    android:oneshot="false">
    <item android:drawable="@drawable/loading_1" android:duration="100" />
    <item android:drawable="@drawable/loading_2" android:duration="100" />
    <item android:drawable="@drawable/loading_3" android:duration="100" />
    <item android:drawable="@drawable/loading_4" android:duration="100" />
    <item android:drawable="@drawable/loading_5" android:duration="100" />
    <item android:drawable="@drawable/loading_6" android:duration="100" />
    <item android:drawable="@drawable/loading_7" android:duration="100" />
    <item android:drawable="@drawable/loading_8" android:duration="100" />
    <item android:drawable="@drawable/loading_9" android:duration="100" />
    <item android:drawable="@drawable/loading_10" android:duration="100" />
    <item android:drawable="@drawable/loading_11" android:duration="100" />
    <item android:drawable="@drawable/loading_12" android:duration="100" />
    </animation-list>

    MyActivity.java

    import android.app.Activity;
    import android.graphics.drawable.AnimationDrawable;
    import android.os.Bundle;
    import android.widget.ImageView;
    import android.widget.LinearLayout;

     

    public class MyActivity extends Activity {

    ImageView loading;
    AnimationDrawable loadAnimation;

    public void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    LinearLayout main = new LinearLayout(this);
    main.setOrientation(LinearLayout.VERTICAL);
    setContentView(main);

    loading = new ImageView(this);
    loading.setImageResource(R.drawable.loading);
    loadAnimation = (AnimationDrawable)loading.getDrawable();
    main.addView(loading);

    }

     

    //can't start animating in OnCreate, so start when window becomes in focus
    @Override
    public void onWindowFocusChanged(boolean hasFocus){

    loadAnimation.start();

    }

    }

  • 相关阅读:
    House of hello恶搞包之真假辨别
    Window phone用手机来控制电脑的多媒体播放
    《你是我的小羊驼》游戏ios源码
    打地鼠游戏ios源码
    Android系统的架构
    魔兽塔防游戏android源码
    抢滩登陆游戏android源码
    Java学生管理系统项目案例
    UITextView如何关闭键盘
    view上添加点手势 button无法响应点击事件
  • 原文地址:https://www.cnblogs.com/fx2008/p/3141382.html
Copyright © 2020-2023  润新知