【问题标题】:Android, Animation in progress bar doesn't runAndroid,动画进度条不运行
【发布时间】:2012-02-25 09:11:32
【问题描述】:

在我的应用程序中,我想覆盖进度条的默认外观。默认一个是矩形并且有加载动画。那么,我做了什么?

首先在 res/drawable 中我创建了 loadinganim.xml(loading01-6 是我的 .png 图像)。

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

<animation-list 
    xmlns:android="http://schemas.android.com/apk/res/android"  
    android:oneshot="false" >  

    <item android:drawable="@drawable/loading01" android:duration="300" />  
    <item android:drawable="@drawable/loading02" android:duration="300" />  
    <item android:drawable="@drawable/loading03" android:duration="300" />  
    <item android:drawable="@drawable/loading04" android:duration="300" />  
    <item android:drawable="@drawable/loading05" android:duration="300" />  
    <item android:drawable="@drawable/loading06" android:duration="300" /> 

</animation-list>  

然后在 res\layout 中,我创建了另一个 xml 文件,名为 layout_loading.xml。

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

<ImageView  
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/blankImageView"  
    android:layout_width="wrap_content"  
    android:layout_height="wrap_content"  
    android:src="@drawable/loading01"/>

在代码中,我有一个按钮,当您按下它时会出现进度条。代码是:

private ProgressDialog progressBar;
private AnimationDrawable myAnimation;

Button btnCustom1 = (Button) findViewById(R.id.custom1);
        btnCustom1.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                progressBar = ProgressDialog.show(MainActivity.this, "", "");
                progressBar.setContentView(R.layout.layout_loading);
                progressBar.setCancelable(true);
                final ImageView imageView = (ImageView) progressBar.findViewById(R.id.blankImageView); 
                imageView.setBackgroundResource(R.drawable.loadinganim);
                myAnimation = (AnimationDrawable) imageView.getBackground();
                myAnimation.start(); 
            }
        });

问题是当我点击按钮时,图像会显示但没有动画。如下图。请告诉我如何运行动画?还是我的错在哪里?

谢谢你帮助我。

【问题讨论】:

    标签: android animation custom-controls progress-bar custom-action


    【解决方案1】:

    我找到了答案。

    其实上面的代码没有问题,而且是正确的。不显示动画的原因是由于 Android 2.3.3(API 10)中的一个错误(至少,我认为)。当我在其他模拟器(API 15)上运行该项目时,它的动画效果很好,没有任何问题。

    因此,嘿 Google 家伙,请做一些真正的错误。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-04-23
      • 1970-01-01
      • 2011-12-23
      • 2016-12-10
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多