Android中自定义的加载对话框和加载条


先分享一个常用的转动形式加载对话框。


这个是很早前一个应用,一哥们写的控件。

后来发现联想的应用中基本所用应用加载框都是这个。(开源代码没版权一说吧)

控件比较简单,分享下思路:

1.首先这是一个自定义的dialog,重写了dialog,系统的progressdialog也是继承了dialog。

[java]

  1. /** 
  2.  * @author Nono 
  3.  *  
  4.  */  
  5. public class CustomProgressBarDialog extends Dialog {  
  6.     private LayoutInflater inflater;  
  7.     private Context mContext;  
  8.     private LayoutParams lp;  
  9.   
  10.     /** 
  11.      * @param context 
  12.      */  
  13.     public CustomProgressBarDialog(Context context) {  
  14.         super(context, R.style.NoTitleDialog);  
  15.         this.mContext = context;  
  16.         inflater = (LayoutInflater) mContext  
  17.                 .getSystemService(Context.LAYOUT_INFLATER_SERVICE);  
  18.         layout = inflater.inflate(R.layout.custom_progressbar, null);  
  19.         setContentView(layout);  
  20.         // 设置window属性   
  21.         lp = getWindow().getAttributes();  
  22.         lp.gravity = Gravity.CENTER;  
  23.         lp.dimAmount = 0// 去背景遮盖   
  24.         lp.alpha = 1.0f;  
  25.         getWindow().setAttributes(lp);  
  26.   
  27.     }  
  28.   
  29. }  
2.主要是setContentView(view)中的这个view该如何定义。

[java]

  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <LinearLayout xmlns:Android="http://schemas.android.com/apk/res/android"  
  3.     android:orientation="horizontal" android:layout_width="fill_parent"  
  4.     android:layout_height="wrap_content" android:gravity="center">  
  5.     <ProgressBar xmlns:android="http://schemas.android.com/apk/res/android"  
  6.         android:layout_width="wrap_content" android:layout_height="wrap_content"  
  7.         style="@style/CustomProgessBarStyle" android:padding="10dip"  
  8.         android:layout_gravity="center" android:gravity="center"  
  9.          />  
  10.     <TextView android:id="@+id/load_info_text" android:text="@string/loading" android:layout_width="wrap_content"  
  11.         android:layout_height="wrap_content" android:textColor="#FFFFFF"  
  12.         android:padding="10dip" />  
  13. </LinearLayout>  
3.上面的核心代码就是那个style,下面我们看下这个style代码;

[html]

  1. <style name="CustomProgessBarStyle">  
  2.         <item name="android:indeterminateDrawable">@drawable/custom_progress_bar</item>  
  3.         <item name="android:minWidth">50dip</item>  
  4.         <item name="android:maxWidth">50dip</item>  
  5.         <item name="android:minHeight">50dip</item>  
  6.         <item name="android:maxHeight">50dip</item>  
  7.     </style>  
4.我们看第一个item,也就是不稳定的图片,也是关键代码。自定义的drawable,我们知道res下的drawable文件中可以定义多种样式的drawable资源文件,
  • 1
  • 2
  • 下一页

相关内容