zoukankan      html  css  js  c++  java
  • 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();

    }

    }

  • 相关阅读:
    ListView的使用(二)长按弹出上下文菜单
    自己遇到程序安装完图标不显示记录
    ListView的使用(一)
    Docker 构建私有镜像仓库
    DockerFile 编译语法详解
    Docker 添加容器SSH服务
    Docker 数据卷与容器互联
    Docker 镜像与容器管理
    Docker 容器简介与部署
    Zabbix-自带监控项与Kye
  • 原文地址:https://www.cnblogs.com/fx2008/p/3141382.html
Copyright © 2011-2022 走看看