這個問題已經被問到,但我沒有找到任何合適的答案,所以我發佈的問題。 我有一個ProgressBar
動畫,它具有多個圖像並像加載欄一樣加載這些圖像。我能夠在4.0及更高版本中成功運行它,但它在2.3中不起作用。如何使它在較低版本中工作?動畫Drawable not in GingerBread
我的動畫繪製對象XML文件
<?xml version="1.0" encoding="utf-8"?>
<animation-list xmlns:android="http://schemas.android.com/apk/res/android"
android:oneshot="false"
android:pivotX="50%"
android:pivotY="50%" >
<item android:drawable="@drawable/p1_wheel" android:duration="200"/>
<item android:drawable="@drawable/p2_wheel" android:duration="200"/>
<item android:drawable="@drawable/p3_wheel" android:duration="200"/>
<item android:drawable="@drawable/p4_wheel" android:duration="200"/>
<item android:drawable="@drawable/p5_wheel" android:duration="200"/>
<item android:drawable="@drawable/p6_wheel" android:duration="200"/>
<item android:drawable="@drawable/p7_wheel" android:duration="200"/>
<item android:drawable="@drawable/p8_wheel" android:duration="200"/>
<item android:drawable="@drawable/p9_wheel" android:duration="200"/>
<item android:drawable="@drawable/p10_wheel" android:duration="200"/>
<item android:drawable="@drawable/p11_wheel" android:duration="200"/>
<item android:drawable="@drawable/p12_wheel" android:duration="200"/>
</animation-list>
我的XML文件
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<ImageView
android:id="@+id/imageView1"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_centerInParent="true"/>
</RelativeLayout>
我的Java文件
package com.example.progressbarsample;
import android.os.Bundle;
import android.app.Activity;
import android.graphics.drawable.AnimationDrawable;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.DrawableContainer;
import android.view.Menu;
import android.widget.ImageView;
import android.widget.ProgressBar;
public class MainActivity extends Activity {
ImageView progressbar;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
progressbar = (ImageView) findViewById(R.id.imageView1);
progressbar.setBackgroundResource(R.drawable.progressbar);
final AnimationDrawable frame = (AnimationDrawable) progressbar.getBackground();
progressbar.post(new Runnable() {
@Override
public void run() {
frame.start();
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
什麼是您的最低SDK版本? – Piyush
@PiyushGupta Min SDK是10 – Saraschandraa
您是否遇到錯誤或者只有它不工作? – Mert