重慶分公司,新征程啟航
為企業提供網站建設、域名注冊、服務器等服務
為企業提供網站建設、域名注冊、服務器等服務
Android中怎么實現加載對話框效果,針對這個問題,這篇文章詳細介紹了相對應的分析和解答,希望可以幫助更多想解決這個問題的小伙伴找到更簡單易行的方法。
成都創新互聯公司是一家集網站建設,龍鳳企業網站建設,龍鳳品牌網站建設,網站定制,龍鳳網站建設報價,網絡營銷,網絡優化,龍鳳網站推廣為一體的創新建站企業,幫助傳統企業提升企業形象加強企業競爭力。可充分滿足這一群體相比中小企業更為豐富、高端、多元的互聯網需求。同時我們時刻保持專業、時尚、前沿,時刻以成就客戶成長自我,堅持不斷學習、思考、沉淀、凈化自己,讓我們為更多的企業打造出實用型網站。
第一種方式:使用動畫讓一個圖片旋轉
然后自定義Alertdialog,并對圖片添加旋轉動畫:
public class LoadingDialog extends AlertDialog { private final String DEFAULT_TEXT="正在加載"; private ImageView mImageview; private TextView mTextView; private LinearLayout mLayout; private String mText; protected LoadingDialog(Context context) { super(context); // TODO Auto-generated constructor stub } @Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); mLayout=(LinearLayout) LinearLayout.inflate(getContext(), R.layout.loading_dialog, null); mImageview=(ImageView) mLayout.findViewById(R.id.loading_dialog_pic); mTextView=(TextView) mLayout.findViewById(R.id.loading_dialog_text); loadanimation(); getWindow().setContentView(mLayout); } private void loadanimation() {//對圖片添加旋轉動畫 // TODO Auto-generated method stub Animation anim=AnimationUtils.loadAnimation(getContext(), R.anim.loading_dialog_anim); LinearInterpolator lin = new LinearInterpolator(); anim.setInterpolator(lin); mImageview.setAnimation(anim); }}
看一下xml的動畫:
第二種方式:使用progressbar
首先是一個animation-list:
看一下布局的實現:
然后自定義一個alertdialog:
public class LoadingDialog extends AlertDialog { private final String DEFAULT_TEXT="正在加載"; private TextView mTextView; private LinearLayout mLayout; private String mText; protected LoadingDialog(Context context) { super(context); // TODO Auto-generated constructor stub } @Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); mLayout=(LinearLayout) LinearLayout.inflate(getContext(), R.layout.loading_dialog, null); mTextView=(TextView) mLayout.findViewById(R.id.loading_dialog_text); WindowManager m=(WindowManager) getContext().getSystemService(getContext().WINDOW_SERVICE); int windowwith=m.getDefaultDisplay().getWidth(); int w=windowwith*3/5; int h=300; getWindow().setLayout(w, h);//設置對話框窗體大小 getWindow().setContentView(mLayout); }}
關于Android中怎么實現加載對話框效果問題的解答就分享到這里了,希望以上內容可以對大家有一定的幫助,如果你還有很多疑惑沒有解開,可以關注創新互聯行業資訊頻道了解更多相關知識。