您的位置:首页 > 移动开发 > Android开发

android自定义加载动画

2017-05-08 10:35 375 查看
http://blog.csdn.net/u012483116/article/details/51192564



1.首先为动画的布局

[html] view
plain copy

 





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

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"  

    android:layout_width="match_parent"  

    android:layout_height="match_parent"  

    android:background="@drawable/bg_transparent">  

  

    <LinearLayout  

        android:layout_width="wrap_content"  

        android:layout_height="wrap_content"  

        android:layout_centerInParent="true"  

        android:background="@drawable/progress_pop_bg"  

        android:orientation="vertical"  

        android:padding="30dp">  

  

        <ProgressBar  

            android:layout_width="wrap_content"  

            android:layout_height="wrap_content"  

            android:indeterminateDrawable="@anim/anim_progress"  

            android:indeterminateDuration="1000" />  

        <TextView  

            android:id="@+id/tv_progress"  

            android:layout_width="wrap_content"  

            android:layout_height="wrap_content"  

            android:layout_gravity="center_horizontal"  

            android:layout_marginTop="20dp"  

            android:background="@color/white"  

            android:text="加载中..."  

            android:textColor="#f976a8" />  

    </LinearLayout>  

  

  

</RelativeLayout>  

2.为加载动画的工具类

[java] view
plain copy

 





import android.app.Activity;  

import android.app.AlertDialog;  

import android.app.ProgressDialog;  

import android.content.Context;  

import android.graphics.drawable.BitmapDrawable;  

import android.view.Gravity;  

import android.view.LayoutInflater;  

import android.view.View;  

import android.view.ViewGroup;  

import android.widget.PopupWindow;  

  

import com.js.phoneforplatform.R;  

  

/** 

 * Created by Administrator on 2016/4/15. 

 */  

public class ProgressUtils {  

    private static PopupWindow mPopupWindow;  

    public static void showProgress(Context context) {  

        View progressView = LayoutInflater.from(context).inflate(R.layout.layout_progress, null);  

        showPopupWindow(progressView);  

    }  

  

  

  

    private static void showPopupWindow(View popupView) {  

        mPopupWindow = new PopupWindow(popupView, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);  

        mPopupWindow.setFocusable(true);  

        mPopupWindow.setOutsideTouchable(false);  

        mPopupWindow.update();  

        mPopupWindow.setBackgroundDrawable(new BitmapDrawable());  

        mPopupWindow.showAtLocation(popupView, Gravity.CENTER, 0, 0);  

    }  

  

    public static void dismissProgress() {  

        if (mPopupWindow != null && mPopupWindow.isShowing()) {  

            mPopupWindow.dismiss();  

        }  

    }  

}  

3.调用方法很简单开始加载为ProgressUtils.showPopupWindow(this)。停止为ProgressUtils.dismissProgress();

4.用到的附件:

progress_pop_bg.xml

[html] view plain copy 



<?xml version="1.0" encoding="utf-8"?>  
<shape xmlns:android="http://schemas.android.com/apk/res/android"  
    android:shape="rectangle">  
    <corners android:radius="2dp"></corners>  
    <solid android:color="@color/white"></solid>  
    <stroke  
        android:width="1dp"  
        android:color="@color/white"></stroke>  
  
</shape>  

anim_progress.xml
[html] view plain copy 



<?xml version="1.0" encoding="utf-8"?>  
<rotate xmlns:android="http://schemas.android.com/apk/res/android"  
    android:drawable="@drawable/search_buffer"  
    android:pivotX="50%"  
    android:pivotY="50%">  
</rotate>  

图片






顶0
 
踩0

 

 
上一篇http相关辅助工具类
下一篇android验证电话号码工具类
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: