0
在我的应用程序中,我想覆盖进度条的默认外观。默认的是一个矩形,并具有加载动画。那么,我做了什么?Android,进行中的动画栏不运行
首先在res/drawable我创建了loadanim.xml(loading 01-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中,我创建了另一个名为layout_loading.xml的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();
}
});
问题是当我点击按钮,图像会显示,但没有动画。像下面的图片。请告诉我如何运行动画?或我的错在哪里?
谢谢你帮助我。