真实的国产乱ⅩXXX66竹夫人,五月香六月婷婷激情综合,亚洲日本VA一区二区三区,亚洲精品一区二区三区麻豆

成都創(chuàng)新互聯(lián)網(wǎng)站制作重慶分公司

Android實(shí)現(xiàn)自定義加載框的代碼示例

App在與服務(wù)器進(jìn)行網(wǎng)絡(luò)交互的時(shí)候,需要有一個(gè)提示的加載框,如圖:

創(chuàng)新互聯(lián)服務(wù)項(xiàng)目包括濮陽網(wǎng)站建設(shè)、濮陽網(wǎng)站制作、濮陽網(wǎng)頁制作以及濮陽網(wǎng)絡(luò)營銷策劃等。多年來,我們專注于互聯(lián)網(wǎng)行業(yè),利用自身積累的技術(shù)優(yōu)勢(shì)、行業(yè)經(jīng)驗(yàn)、深度合作伙伴關(guān)系等,向廣大中小型企業(yè)、政府機(jī)構(gòu)等提供互聯(lián)網(wǎng)行業(yè)的解決方案,濮陽網(wǎng)站推廣取得了明顯的社會(huì)效益與經(jīng)濟(jì)效益。目前,我們服務(wù)的客戶以成都為中心已經(jīng)輻射到濮陽省份的部分城市,未來相信會(huì)繼續(xù)擴(kuò)大服務(wù)區(qū)域并繼續(xù)獲得客戶的支持與信任!

Android實(shí)現(xiàn)自定義加載框的代碼示例

此時(shí)我們可以自定義一個(gè)加載中的對(duì)話框,代碼如下:

public class LoadingDialog extends Dialog { 
private static final int CHANGE_TITLE_WHAT = 1; 
private static final int CHNAGE_TITLE_DELAYMILLIS = 300; 
private static final int MAX_SUFFIX_NUMBER = 3; 
private static final char SUFFIX = '.'; 
 
 
private ImageView iv_route; 
private TextView detail_tv; 
private TextView tv_point; 
private RotateAnimation mAnim; 
 
 
private Handler handler = new Handler() { 
private int num = 0; 
 
 
public void handleMessage(android.os.Message msg) { 
if (msg.what == CHANGE_TITLE_WHAT) { 
StringBuilder builder = new StringBuilder(); 
if (num >= MAX_SUFFIX_NUMBER) { 
num = 0; 
} 
num++; 
for (int i = 0; i < num; i++) { 
builder.append(SUFFIX); 
} 
tv_point.setText(builder.toString()); 
if (isShowing()) { 
handler.sendEmptyMessageDelayed(CHANGE_TITLE_WHAT, CHNAGE_TITLE_DELAYMILLIS); 
} 
else { 
num = 0; 
} 
} 
}; 
}; 
 
 
public LoadingDialog(Context context) { 
super(context, R.style.Dialog_bocop); 
init(); 
} 
 
 
public LoadingDialog(Context context, boolean isTrans) { 
super(context, isTrans ? R.style.Loading_Dialog_trans : R.style.Dialog_bocop); 
init(); 
} 
 
 
private void init() { 
setContentView(R.layout.common_dialog_loading_layout); 
iv_route = (ImageView) findViewById(R.id.iv_route); 
detail_tv = (TextView) findViewById(R.id.detail_tv); 
tv_point = (TextView) findViewById(R.id.tv_point); 
initAnim(); 
getWindow().setWindowAnimations(R.anim.alpha_in); 
} 
 
 
private void initAnim() { 
// mAnim = new RotateAnimation(360, 0, Animation.RESTART, 0.5f, Animation.RESTART, 0.5f); 
mAnim = new RotateAnimation(0, 360, Animation.RESTART, 0.5f, Animation.RESTART, 0.5f); 
mAnim.setDuration(2000); 
mAnim.setRepeatCount(Animation.INFINITE); 
mAnim.setRepeatMode(Animation.RESTART); 
mAnim.setStartTime(Animation.START_ON_FIRST_FRAME); 
} 
 
 
@Override 
public void show() {//在要用到的地方調(diào)用這個(gè)方法 
iv_route.startAnimation(mAnim); 
handler.sendEmptyMessage(CHANGE_TITLE_WHAT); 
super.show(); 
} 
 
 
@Override 
public void dismiss() { 
mAnim.cancel(); 
super.dismiss(); 
} 
 
 
@Override 
public void setTitle(CharSequence title) { 
if (TextUtils.isEmpty(title)) { 
detail_tv.setText("正在加載"); 
} 
else { 
detail_tv.setText(title); 
} 
} 
 
 
@Override 
public void setTitle(int titleId) { 
setTitle(getContext().getString(titleId)); 
} 
 
 
public static void dismissDialog(LoadingDialog loadingDialog) { 
if (null == loadingDialog) { return; } 
loadingDialog.dismiss(); 
} 
} 

-------------對(duì)應(yīng)的布局如下------------------  

<?xml version="1.0" encoding="utf-8"?> 
   
 
 
     
 
 
       
     
 
 
     
 
 
       
 
 
       
     
   

比如在Activity中要實(shí)現(xiàn)加載對(duì)話框調(diào)用 :  

LoadingDialog loadingDialog ; 
 
if (null == loadingDialog) { 
loadingDialog = new LoadingDialog(aty); 
loadingDialog.setOnCancelListener(this); 
} 
loadingDialog.setTitle(“數(shù)據(jù)加載中”); 
if (!loadingDialog.isShowing()) loadingDialog.show(); 

以上就是本文的全部內(nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持創(chuàng)新互聯(lián)。


網(wǎng)站標(biāo)題:Android實(shí)現(xiàn)自定義加載框的代碼示例
URL分享:http://weahome.cn/article/iesjcj.html

其他資訊

在線咨詢

微信咨詢

電話咨詢

028-86922220(工作日)

18980820575(7×24)

提交需求

返回頂部