實現起來還是比較簡單的.看下面的代碼.
package com.ql.app;
import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.Gravity;
import android.widget.ImageView;
import android.widget.LinearLayout;
public class App extends Activity {
private LinearLayout layout;
private Handler handler;
private int number=10;
private ImageView[] imageViews=new ImageView[number];
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
handler=new Handler(){
@Override
public void handleMessage(Message msg) {
//效率比較低
// for(int i=0;i<number;i++){
// imageViews[i].setBackgroundResource(i==msg.what?R.drawable.progress_go_small:R.drawable.progress_bg_small);
// }
//這樣效率高
imageViews[msg.what].setBackgroundResource(R.drawable.progress_go_small);
if(msg.what==0){
msg.what=number;
}
imageViews[msg.what-1].setBackgroundResource(R.drawable.progress_bg_small);
}
};
initViews();
playAnimation();
}
private void initViews(){
layout=(LinearLayout)findViewById(R.id.layout);
LinearLayout container=new LinearLayout(this);
container.setOrientation(LinearLayout.HORIZONTAL);
container.setGravity(Gravity.CENTER);
LinearLayout.LayoutParams lp=new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT,LinearLayout.LayoutParams.FILL_PARENT);
lp.gravity=Gravity.CENTER;
LinearLayout.LayoutParams params=new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,LinearLayout.LayoutParams.WRAP_CONTENT);
for(int i=0;i<number;i++){
imageViews[i]=new ImageView(this);
imageViews[i].setBackgroundResource(i==0?R.drawable.progress_go_small:R.drawable.progress_bg_small);
container.addView(imageViews[i], params);
}
layout.addView(container,lp);
}
//不斷發送消息,切換圖片
private void playAnimation() {
new Thread() {
@Override
public void run() {
while (true) {
for (int i = 0; i < number; i++) {
handler.sendEmptyMessage(i);
try {
this.sleep(300);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
}.start();
}
}
一個比較笨的實現:
http://gundumw100.iteye.com/admin/blogs/1052266
更多文章、技術交流、商務合作、聯系博主
微信掃碼或搜索:z360901061
微信掃一掃加我為好友
QQ號聯系: 360901061
您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。
【本文對您有幫助就好】元

