【发布时间】: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