方式一:帧动画切换效果(几张图片切换)

1.drawable 下创建资源(多张图片~根据自己需要)

<?xml version="1.0" encoding="utf-8"?>
<animation-list xmlns:android="http://schemas.android.com/apk/res/android"><itemandroid:drawable="@drawable/a"android:duration="150"/><itemandroid:drawable="@drawable/b"android:duration="150"/><itemandroid:drawable="@drawable/c"android:duration="150"/>
</animation-list>

2.mydialog.xml(普通布局)

<?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:orientation="vertical"><ImageViewandroid:id="@+id/loadingIv"android:layout_width="30dp"android:layout_height="40dp"android:layout_centerInParent="true"android:background="@drawable/s"/><TextViewandroid:id="@+id/loadingTv"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_below="@+id/loadingIv"android:layout_centerHorizontal="true"android:layout_marginTop="15dp"android:text="加载中...."android:textColor="#fff"android:textSize="15dp"/>
</RelativeLayout>

3.MyDialog类:

public class MyDialog extends ProgressDialog{private AnimationDrawable mAnimation;private ImageView mImageView;private TextView mTextView;private String loadingTip;private int resid;/**** @param context 上下文对象* @param content 显示文字提示信息内容* @param id 动画id*/public MyDialog(Context context, String content, int resid) {super(context);this.loadingTip = content;this.resid = resid;//点击提示框外面是否取消提示框setCanceledOnTouchOutside(false);//点击返回键是否取消提示框setCancelable(false);setIndeterminate(true);}@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.dialog);mTextView = (TextView) findViewById(R.id.loadingTv);mImageView = (ImageView) findViewById(R.id.loadingIv);mImageView.setBackgroundResource(resid);// 通过ImageView对象拿到背景显示的AnimationDrawablemAnimation = (AnimationDrawable) mImageView.getBackground();mImageView.post(new Runnable() {@Overridepublic void run() {mAnimation.start();}});mTextView.setText(loadingTip);}
}
//最后在activity中进行调用,这样就完成了一个自定义的dialog提示框

4.需要dialog的Activity写下方法,调用即可

 public void showMyDialog() {dialog = new MyDialog(this, "正在加载中", R.drawable.s);dialog.show();Handler handler = new Handler();handler.postDelayed(new Runnable() {@Overridepublic void run() {dialog.dismiss();}}, 5000);}

方式二:圆形彩球旋转效果

1.建类 EaseInOutCubicInterpolator(复制)

public class EaseInOutCubicInterpolator implements TimeInterpolator{@Overridepublic float getInterpolation(float input) {if ((input *= 2) < 1.0f) {return 0.5f * input * input * input;}input -= 2;return 0.5f * input * input * input + 1;}
}

2.建menu文件夹,建xml

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"xmlns:app="http://schemas.android.com/apk/res-auto"xmlns:tools="http://schemas.android.com/tools"tools:context=".MainActivity"><item android:id="@+id/action_settings"android:title="Settings"android:orderInCategory="100"app:showAsAction="never"/>
</menu>

3.values下dimens.xml中添加

<dimen name="default_circle_view_size">200dp</dimen>

4.values下建attrs

<?xml version="1.0" encoding="utf-8"?>
<resources> <declare-styleable name="CircleProgress"><attr name="color1" format="reference|color"/><attr name="color2" format="reference|color"/><attr name="color3" format="reference|color"/>
</declare-styleable>
</resources>

5.自定义view,复制

public class CircleProgress extends View {private static final int RED = 0xFFE5282C;private static final int YELLOW = 0xFF1F909A;private static final int BLUE = 0xFFFC9E12;private static final int COLOR_NUM = 3;private int[] COLORS;private TimeInterpolator mInterpolator = new EaseInOutCubicInterpolator();private final double DEGREE = Math.PI / 180;private Paint mPaint;private int mViewSize;private int mPointRadius;private long mStartTime;private long mPlayTime;private boolean mStartAnim = false;private Point mCenter = new Point();private ArcPoint[] mArcPoint;private static final int POINT_NUM = 15;private static final int DELTA_ANGLE = 360 / POINT_NUM;private long mDuration = 3600;public CircleProgress(Context context) {super(context);init(null, 0);}public CircleProgress(Context context, AttributeSet attrs) {super(context, attrs);init(attrs, 0);}public CircleProgress(Context context, AttributeSet attrs, int defStyle) {super(context, attrs, defStyle);init(attrs, defStyle);}private void init(AttributeSet attrs, int defStyle) {mArcPoint = new ArcPoint[POINT_NUM];mPaint = new Paint();mPaint.setAntiAlias(true);mPaint.setStyle(Paint.Style.FILL);TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.CircleProgress, defStyle, 0);int color1 = a.getColor(R.styleable.CircleProgress_color1, RED);int color2 = a.getColor(R.styleable.CircleProgress_color2, YELLOW);int color3 = a.getColor(R.styleable.CircleProgress_color3, BLUE);a.recycle();COLORS = new int[]{color1, color2, color3};}@Overrideprotected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {int defaultSize = getResources().getDimensionPixelSize(R.dimen.default_circle_view_size);int width = getDefaultSize(defaultSize, widthMeasureSpec);int height = getDefaultSize(defaultSize, heightMeasureSpec);mViewSize = Math.min(width, height);setMeasuredDimension(mViewSize, mViewSize);mCenter.set(mViewSize / 2, mViewSize / 2);calPoints(1.0f);}@Overrideprotected void onDraw(Canvas canvas) {canvas.save();canvas.translate(mCenter.x, mCenter.y);float factor = getFactor();canvas.rotate(36 * factor);float x, y;for (int i = 0; i < POINT_NUM; ++i) {mPaint.setColor(mArcPoint[i].color);float itemFactor = getItemFactor(i, factor);x = mArcPoint[i].x - 2 * mArcPoint[i].x * itemFactor;y = mArcPoint[i].y - 2 * mArcPoint[i].y * itemFactor;canvas.drawCircle(x, y, mPointRadius, mPaint);}canvas.restore();if (mStartAnim) {postInvalidate();}}private void calPoints(float factor) {int radius = (int) (mViewSize / 3 * factor);mPointRadius = radius / 12;for (int i = 0; i < POINT_NUM; ++i) {float x = radius * -(float) Math.sin(DEGREE * DELTA_ANGLE * i);float y = radius * -(float) Math.cos(DEGREE * DELTA_ANGLE * i);ArcPoint point = new ArcPoint(x, y, COLORS[i % COLOR_NUM]);mArcPoint[i] = point;}}private float getFactor() {if (mStartAnim) {mPlayTime = AnimationUtils.currentAnimationTimeMillis() - mStartTime;}float factor = mPlayTime / (float) mDuration;return factor % 1f;}private float getItemFactor(int index, float factor) {float itemFactor = (factor - 0.66f / POINT_NUM * index) * 3;if (itemFactor < 0f) {itemFactor = 0f;} else if (itemFactor > 1f) {itemFactor = 1f;}return mInterpolator.getInterpolation(itemFactor);}public void startAnim() {mPlayTime = mPlayTime % mDuration;mStartTime = AnimationUtils.currentAnimationTimeMillis() - mPlayTime;mStartAnim = true;postInvalidate();}public void reset() {stopAnim();mPlayTime = 0;postInvalidate();}public void stopAnim() {mStartAnim = false;}public void setInterpolator(TimeInterpolator interpolator) {mInterpolator = interpolator;}public void setDuration(long duration) {mDuration = duration;}public void setRadius(float factor) {stopAnim();calPoints(factor);startAnim();}static class ArcPoint {float x;float y;int color;ArcPoint(float x, float y, int color) {this.x = x;this.y = y;this.color = color;}}
}

6.写类MyProgressDialog extends ProgressDialog,对应布局main_dialog.xml

public class MyProgressDialog extends ProgressDialog{protected CircleProgress mProgress;protected TextView mLoadingTv;//private AnimationDrawable mAnimation;public MyProgressDialog(Context context) {super(context);//点击提示框外面是否取消提示框setCanceledOnTouchOutside(false);//点击返回键是否取消提示框setCancelable(false);setIndeterminate(true);}@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.main_dialog);initView();//弹出dialogmProgress.post(new Runnable() {@Overridepublic void run() {mProgress.startAnim();}});}@Overridepublic boolean onCreateOptionsMenu(Menu menu) {// Inflate the menu; this adds items to the action bar if it is present.getOwnerActivity().getMenuInflater().inflate(R.menu.main_menu_main, menu);return true;}@Overridepublic boolean onOptionsItemSelected(MenuItem item) {// Handle action bar item clicks here. The action bar will// automatically handle clicks on the Home/Up button, so long// as you specify a parent activity in AndroidManifest.xml.int id = item.getItemId();//noinspection SimplifiableIfStatementif (id == R.id.action_settings) {return true;}return super.onOptionsItemSelected(item);}private void initView() {mProgress = (CircleProgress)findViewById(R.id.progress);mLoadingTv = (TextView)findViewById(R.id.loadingTv);}
}

7.布局main_dialog.xml(用自定义view)

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayoutxmlns:android="http://schemas.android.com/apk/res/android"xmlns:tools="http://schemas.android.com/tools"android:layout_width="match_parent"android:layout_height="match_parent"xmlns:circleprogress="http://schemas.android.com/apk/res-auto"tools:context="a1113duoji.qf.com.loding.MainActivity"><a1113duoji.qf.com.loding.CircleProgressandroid:id="@+id/progress"android:layout_width="100dp"android:layout_height="100dp"android:layout_centerHorizontal="true"android:layout_centerVertical="true"circleprogress:color1="@android:color/holo_red_light"circleprogress:color2="@android:color/holo_green_light"circleprogress:color3="@android:color/holo_blue_light"/><TextViewandroid:id="@+id/loadingTv"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_alignLeft="@+id/progress"android:layout_alignStart="@+id/progress"android:layout_below="@+id/progress"android:text="正在加载中.."android:textSize="15sp"/>
</RelativeLayout>

8.需要效果的Activity 写入下方法调用

public void showMyDialog() {MyProgressDialog    dialog = new MyProgressDialog(this);//=============上下文dialog.show();dialog.getWindow().setBackgroundDrawable(new ColorDrawable(0));Handler handler = new Handler();handler.postDelayed(new Runnable() {@Overridepublic void run() {dialog.dismiss();}}, 5000);//================动画的时间}

效果图如下(此图来自于:https://github.com/Fichardu/CircleProgress)

方式三:几个图片上下跳动效果

1.导包

compile 'com.github.zzz40500:android-shapeLoadingView:1.0.3.2'
//弹出小框需添加下面的
repositories {
        maven {
            url "https://jitpack.io"
        }

    }

2.建menu文件夹,建xml

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"xmlns:app="http://schemas.android.com/apk/res-auto"><item android:id="@+id/action_settings" android:title="@string/action_settings"android:orderInCategory="100" app:showAsAction="never" />
</menu>

3.string 资源需添加

<resources><string name="action_settings">Settings</string>
</resources>

4.mydialog.xml 布局中

<com.mingle.widget.LoadingViewandroid:id="@+id/loadView"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_gravity="center_horizontal"android:paddingTop="50dp"app:loadingText="加载中..."/>

5.MyDialog 类(复制不变)

public class MyDialog extends ProgressDialog {protected LoadingView mLoadView;public MyDialog(Context context) {super(context);//点击提示框外面是否取消提示框setCanceledOnTouchOutside(false);//点击返回键是否取消提示框setCancelable(false);setIndeterminate(true);}@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.dia);mLoadView = (LoadingView) findViewById(R.id.loadView);}@Overridepublic boolean onCreateOptionsMenu(Menu menu) {// Inflate the menu; this adds items to the action bar if it is present.
//        getMenuInflater().inflate(R.menu.menu_view_demo, menu);return true;}@Overridepublic boolean onOptionsItemSelected(MenuItem item) {// Handle action bar item clicks here. The action bar will// automatically handle clicks on the Home/Up button, so long// as you specify a parent activity in AndroidManifest.xml.int id = item.getItemId();//noinspection SimplifiableIfStatementif (id == R.id.action_settings) {return true;}return super.onOptionsItemSelected(item);}
}

6.需要dialog的Activity,写此方法,oncreate下调用

 public void showMyDialog() {mMyDialog = new MyDialog(this);mMyDialog.show();Handler handler = new Handler();handler.postDelayed(new Runnable() {@Overridepublic void run() {mMyDialog.dismiss();}}, 5000);}

效果图如下(此图来自于:https://github.com/zzz40500/android-shapeLoadingView)

Dialog加载页面动画(Loding.....加载等待)三种方式相关推荐

  1. android 加阴影,Android设置控件阴影的三种方式

    释放双眼,带上耳机,听听看~! 第一种方式:elevation View的大小位置都是通过x,y确定的,而现在有了z轴的概念,而这个z值就是View的高度(elevation),而高度决定了阴影(sh ...

  2. android圆形点击效果,Android 三种方式实现自定义圆形页面加载中效果的进度条

    [实例简介] Android 三种方式实现自定义圆形页面加载中效果的进度条 [实例截图] [核心代码] ad376a86-a9aa-49bc-8cea-321bcff2c0c3 └── AnimRou ...

  3. 加载gif动画的三种方式

    GifView.h/*** 调用结束就开始播放动画,如果需要用户指定何时播放的话,只需要把timer的开始放到合适的位置.通过对CFDictonaryRaf 也就是gifProperties的改变,我 ...

  4. Echarts加载地图的三种方式

    参考地址:http://www.echartsjs.com/option.html#geo.map ECharts 中提供了两种格式的地图数据,一种是可以直接 script 标签引入的 js 文件,引 ...

  5. ios网络学习------4 UIWebView的加载本地数据的三种方式

    ios网络学习------4 UIWebView的加载本地数据的三种方式 分类: IOS2014-06-27 12:56 959人阅读 评论(0) 收藏 举报 UIWebView是IOS内置的浏览器, ...

  6. hbase 协处理器 部署_HBase协处理器加载的三种方式

    本文主要给大家罗列了hbase协处理器加载的三种方式:shell加载(动态).api加载(动态).配置文件加载(静态).其中静态加载方式需要重启hbase. 我们假设我们已经有一个现成的需要加载的协处 ...

  7. HTML5实现动画三种方式

    HTML5实现动画三种方式 编者注:作者以一个运动的小车为例子,讲述了三种实现HTML5动画的方式,思路清晰,动画不仅仅是Canvas,还有css3和javascript.通过合理的选择,来实现最优的 ...

  8. html5 小车动画_HTML5实现动画三种方式

    编者注:作者以一个运动的小车为例子,讲述了三种实现HTML5动画的方式,思路清晰,动画不仅仅是canvas,还有css3和javascript.通过合理的选择,来实现最优的实现. PS:由于显卡.录制 ...

  9. JavaScript--------------------jQuery中.bind() .live() .delegate() .on()的区别 和 三种方式写光棒事件 动画...

    bind(type,[data],fn) 为每个匹配元素的特定事件绑定事件处理函数. $("a").bind("click",function(){alert( ...

  10. vue路由传参的三种方式/含页面刷新参数丢失解决方案(详细)

    vue路由传参的三种方式以及页面刷新参数丢失问题 一.路由传参的三种方式 1.传参方式一:params传参 2.传参方式二:路由属性配置传参 3.传参方式三:query传参 二.三种传递方式的区别 一 ...

最新文章

  1. c++排查线程hang住_Kafka学习笔记之kafka高版本Client连接0.9Server引发的血案排查 - 时光飞逝,逝者如斯...
  2. python是用什么语言开发的-专为人工智能和数据科学而生的Go语言,或将取代Python...
  3. [转]ASP.NET效率陷阱——Attributes
  4. DataV 支持 token 验证啦!
  5. 英语什么意思_“你什么意思”用英语怎么说?千万不要说成“What#39;s your meaning?”...
  6. Request-reply messaging
  7. 当前方法的代码已经过优化,因此无法计算表达式的值
  8. 4.3配置自定义情况的Bean实例
  9. mysqldump 工具使用详解——参数选项
  10. Java学习(1)——用显式转换显式字符在Unicode表中的位置
  11. 收藏已久免费下载软件的黑科技网站
  12. 谷歌seo外链Backlinks研究工具推荐
  13. HSPICE物理模型仿真——添加variation时利用seed产生伪随机分布
  14. python字典找相同值_python-找出字典dic中重复值
  15. h5盲盒商城源码 修复版 附带详细教程
  16. Android 开发之初识 Android
  17. 致我们终究拥抱的距离
  18. 荣耀手环6太带劲 大屏时代终来临
  19. 【Proteus仿真】Arduino UNO+uln2003驱动步进电机+按键启保停正反转控制
  20. java 支付宝退款、提现(单笔转账到支付宝账户接口)

热门文章

  1. 苹果手机通话记录删除了怎么恢复?
  2. 香港服务器怎么加速?
  3. 学编程难吗?多久能入门?
  4. Linux操作系统平台
  5. 你的工作表现是否成熟,用这4条检验自己
  6. Ubuntu 20.04 系统自带中文输入法在PyCharm只能输入3个字母的问题
  7. 【数据库和SQL学习笔记】6.SELECT查询4:嵌套查询、对查询结果进行操作
  8. EXTRACT() 提取函数
  9. 【星座】十二星座会因为什么变穷
  10. 逍遥模拟器获取服务器信息出错,逍遥模拟器不能连上网怎么办?两招解决问题...