日韩久久久精品,亚洲精品久久久久久久久久久,亚洲欧美一区二区三区国产精品 ,一区二区福利

一個簡單的Loading過程

系統(tǒng) 2209 0

一個簡單的Loading過程
實現(xiàn)起來還是比較簡單的.看下面的代碼.
    
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);
    }
    
  //不斷發(fā)送消息,切換圖片
	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();
	}
   
    		
}

  


一個比較笨的實現(xiàn):
http://gundumw100.iteye.com/admin/blogs/1052266

一個簡單的Loading過程


更多文章、技術(shù)交流、商務(wù)合作、聯(lián)系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號聯(lián)系: 360901061

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。

【本文對您有幫助就好】

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長會非常 感謝您的哦!!!

發(fā)表我的評論
最新評論 總共0條評論
主站蜘蛛池模板: 军事| 浦东新区| 丰都县| 北票市| 关岭| 红河县| 建宁县| 峨眉山市| 鸡西市| 西乌珠穆沁旗| 新邵县| 五华县| 佳木斯市| 通榆县| 嫩江县| 华亭县| 含山县| 平度市| 阜平县| 当阳市| 毕节市| 锡林郭勒盟| 察隅县| 吉首市| 泰州市| 陕西省| 射洪县| 雷州市| 彝良县| 六枝特区| 武强县| 孝昌县| 恩平市| 太和县| 稻城县| 宾川县| 沙湾县| 胶州市| 苏尼特左旗| 科技| 永定县|