android自定义加载动画

来源:互联网 发布:药学在职研究生知乎 编辑:程序博客网 时间:2024/05/16 09:42

http://blog.csdn.net/u012483116/article/details/51192564


1.首先为动画的布局

[html] view plain copy
 在CODE上查看代码片派生到我的代码片
  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"  
  3.     android:layout_width="match_parent"  
  4.     android:layout_height="match_parent"  
  5.     android:background="@drawable/bg_transparent">  
  6.   
  7.     <LinearLayout  
  8.         android:layout_width="wrap_content"  
  9.         android:layout_height="wrap_content"  
  10.         android:layout_centerInParent="true"  
  11.         android:background="@drawable/progress_pop_bg"  
  12.         android:orientation="vertical"  
  13.         android:padding="30dp">  
  14.   
  15.         <ProgressBar  
  16.             android:layout_width="wrap_content"  
  17.             android:layout_height="wrap_content"  
  18.             android:indeterminateDrawable="@anim/anim_progress"  
  19.             android:indeterminateDuration="1000" />  
  20.         <TextView  
  21.             android:id="@+id/tv_progress"  
  22.             android:layout_width="wrap_content"  
  23.             android:layout_height="wrap_content"  
  24.             android:layout_gravity="center_horizontal"  
  25.             android:layout_marginTop="20dp"  
  26.             android:background="@color/white"  
  27.             android:text="加载中..."  
  28.             android:textColor="#f976a8" />  
  29.     </LinearLayout>  
  30.   
  31.   
  32. </RelativeLayout>  
2.为加载动画的工具类

[java] view plain copy
 在CODE上查看代码片派生到我的代码片
  1. import android.app.Activity;  
  2. import android.app.AlertDialog;  
  3. import android.app.ProgressDialog;  
  4. import android.content.Context;  
  5. import android.graphics.drawable.BitmapDrawable;  
  6. import android.view.Gravity;  
  7. import android.view.LayoutInflater;  
  8. import android.view.View;  
  9. import android.view.ViewGroup;  
  10. import android.widget.PopupWindow;  
  11.   
  12. import com.js.phoneforplatform.R;  
  13.   
  14. /** 
  15.  * Created by Administrator on 2016/4/15. 
  16.  */  
  17. public class ProgressUtils {  
  18.     private static PopupWindow mPopupWindow;  
  19.     public static void showProgress(Context context) {  
  20.         View progressView = LayoutInflater.from(context).inflate(R.layout.layout_progress, null);  
  21.         showPopupWindow(progressView);  
  22.     }  
  23.   
  24.   
  25.   
  26.     private static void showPopupWindow(View popupView) {  
  27.         mPopupWindow = new PopupWindow(popupView, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);  
  28.         mPopupWindow.setFocusable(true);  
  29.         mPopupWindow.setOutsideTouchable(false);  
  30.         mPopupWindow.update();  
  31.         mPopupWindow.setBackgroundDrawable(new BitmapDrawable());  
  32.         mPopupWindow.showAtLocation(popupView, Gravity.CENTER, 00);  
  33.     }  
  34.   
  35.     public static void dismissProgress() {  
  36.         if (mPopupWindow != null && mPopupWindow.isShowing()) {  
  37.             mPopupWindow.dismiss();  
  38.         }  
  39.     }  
  40. }  
3.调用方法很简单开始加载为ProgressUtils.showPopupWindow(this)。停止为ProgressUtils.dismissProgress();

4.用到的附件:

progress_pop_bg.xml

[html] view plain copy
在CODE上查看代码片派生到我的代码片
  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <shape xmlns:android="http://schemas.android.com/apk/res/android"  
  3.     android:shape="rectangle">  
  4.     <corners android:radius="2dp"></corners>  
  5.     <solid android:color="@color/white"></solid>  
  6.     <stroke  
  7.         android:width="1dp"  
  8.         android:color="@color/white"></stroke>  
  9.   
  10. </shape>  
anim_progress.xml
[html] view plain copy
在CODE上查看代码片派生到我的代码片
  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <rotate xmlns:android="http://schemas.android.com/apk/res/android"  
  3.     android:drawable="@drawable/search_buffer"  
  4.     android:pivotX="50%"  
  5.     android:pivotY="50%">  
  6. </rotate>  
图片



0
 
0
 
 

0 0
原创粉丝点击