android自定义加载动画
2017-05-08 10:35
375 查看
http://blog.csdn.net/u012483116/article/details/51192564
![](http://img.blog.csdn.net/20160419174516689?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center)
1.首先为动画的布局
[html] view
plain copy
![](https://code.csdn.net/assets/CODE_ico.png)
![](https://code.csdn.net/assets/ico_fork.svg)
<?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
![](https://code.csdn.net/assets/CODE_ico.png)
![](https://code.csdn.net/assets/ico_fork.svg)
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
![](https://code.csdn.net/assets/CODE_ico.png)
![](https://code.csdn.net/assets/ico_fork.svg)
<?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
![](https://code.csdn.net/assets/CODE_ico.png)
![](https://code.csdn.net/assets/ico_fork.svg)
<?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>
图片
![](http://img.blog.csdn.net/20160421203844851?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center)
顶0
踩0
上一篇http相关辅助工具类
下一篇android验证电话号码工具类
1.首先为动画的布局
[html] view
plain copy
![](https://code.csdn.net/assets/CODE_ico.png)
<?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
![](https://code.csdn.net/assets/CODE_ico.png)
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
![](https://code.csdn.net/assets/CODE_ico.png)
<?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
![](https://code.csdn.net/assets/CODE_ico.png)
<?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验证电话号码工具类
相关文章推荐
- Android 自定义SurfaceView实现加载GIF动画
- Android自定义带加载动画效果的环状进度条
- android自定义view之加载动画ColorBall
- Android自定义加载loading view动画组件
- android学习-----自定义View 加载动画
- Android-AnimationDrawable自定义加载动画dialog
- android自定义View基础系列一(模仿365日历PC版加载动画)
- Android自定义view-高仿小米视频加载动画效果
- android自定义View---6个小圆组成的加载动画
- Android自定义加载控件实现数据加载动画
- android自定义加载动画
- Android之全屏转圈加载动画和自定义Toast
- Android自定义view利用Xfermode实现动态文字加载动画
- Android自定义加载圈动画效果
- Android自定义view实现阻尼效果的加载动画
- android自定义加载动画
- android自定义加载数据动画dialog和简单的timer计时器
- Android 之自定义加载帧动画
- Android 帧动画实现自定义loading加载框
- Android自定义加载动画