Android 自定义Dialog仿洋米购物

1.定义布局文件

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="#FFFFFF"
    android:gravity="center"
    android:orientation="vertical" >

    <ProgressBar
        style="@style/Translucent_NoTitle"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:gravity="center"
       />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="正在加载。。。" />

</LinearLayout>

2,定义样式主题

    <style name="Translucent_NoTitle" parent="android:style/Theme.Dialog">
        <item name="android:background">#00000000</item>
        <!-- 设置自定义布局的背景透明 -->
        <item name="android:windowBackground">@android:color/transparent</item>
        <item name="android:indeterminateDrawable">@drawable/custom_progress_bar</item>
        <item name="android:minWidth">100dip</item>
        <item name="android:maxWidth">200dip</item>
        <item name="android:minHeight">100dip</item>
        <item name="android:maxHeight">200dip</item>
        <!-- 设置window背景透明,也就是去边框 -->
    </style>

3,定义动画

<?xml version="1.0" encoding="utf-8"?>
<animation-list xmlns:android="http://schemas.android.com/apk/res/android"
    
    android:oneshot="false" android:visible="true" >
      
        
     <item android:drawable="@drawable/mobo_gif_bee_0" android:duration="100" />   
     <item android:drawable="@drawable/mobo_gif_bee_1" android:duration="100" />   
     <item android:drawable="@drawable/mobo_gif_bee_3" android:duration="100" />   
     <item android:drawable="@drawable/mobo_gif_bee_4" android:duration="100" />   
     <item android:drawable="@drawable/mobo_gif_bee_5" android:duration="100" />   
     <item android:drawable="@drawable/mobo_gif_bee_6" android:duration="100" />   
     <item android:drawable="@drawable/mobo_gif_bee_7" android:duration="100" />   
     <item android:drawable="@drawable/mobo_gif_bee_8" android:duration="100" />   
     <item android:drawable="@drawable/mobo_gif_bee_9" android:duration="100" />   
     <item android:drawable="@drawable/mobo_gif_bee_10" android:duration="100" /> 
     <item android:drawable="@drawable/mobo_gif_bee_11" android:duration="100" />   

</animation-list>

4,写一个类继承Dialog

public class MyDialog extends Dialog{

	private LayoutInflater layoutInflater=null;
	private Context mContext;
	private android.view.WindowManager.LayoutParams lp;
	public MyDialog(Context context) {
		this(context,0);	
	}
	public MyDialog(Context context,int id) {
		super(context, R.style.Translucent_NoTitle);
		this.mContext = context;
		layoutInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		View layout = layoutInflater.inflate(R.layout.custom_progressbar, null);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(layout);
		lp = getWindow().getAttributes();
		lp.gravity = Gravity.CENTER;
		lp.dimAmount=0;
		lp.alpha = 1.0f;  
        getWindow().setAttributes(lp);  	
	}



}

  

 

posted @ 2016-02-24 12:58  呼啦啦,,啦啦呼呼  阅读(224)  评论(0编辑  收藏  举报