Android Loading加载动画
1.创建一个工具类LoadingDialog
public class LoadingDialog extends Dialog {private ImageView iv_ing;private AnimationSet animationSet;private static LoadingDialog instance;public static LoadingDialog getInstance(Context context) {if(instance == null) {instance = new LoadingDialog(context);}return instance;}public static void setInstance(LoadingDialog instance) {LoadingDialog.instance = instance;}private LoadingDialog(@NonNull Context context) {super(context);}private LoadingDialog(@NonNull Context context, @StyleRes int themeResId) {super(context, themeResId);}private LoadingDialog(@NonNull Context context, boolean cancelable, @Nullable OnCancelListener cancelListener) {super(context, cancelable, cancelListener);}@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);//背景透明处理getWindow().requestFeature(Window.FEATURE_NO_TITLE);getWindow().setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN,WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN);getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));getWindow().setDimAmount(0f);this.setContentView(R.layout.dialog_loading);//设置dialog属性setCancelable(true);setCanceledOnTouchOutside(false);iv_ing = findViewById(R.id.iv_ing);//加载动画loadIng();}@Overrideprotected void onStart() {super.onStart();iv_ing.startAnimation(animationSet);//开始播放}@Overrideprotected void onStop() {super.onStop();}//加载动画private void loadIng() {animationSet = new AnimationSet(true);RotateAnimation animation_rotate = new RotateAnimation(0, +359,RotateAnimation.RELATIVE_TO_SELF, 0.5f,RotateAnimation.RELATIVE_TO_SELF, 0.5f);//第一个参数fromDegrees为动画起始时的旋转角度 //第二个参数toDegrees为动画旋转到的角度//第三个参数pivotXType为动画在X轴相对于物件位置类型 //第四个参数pivotXValue为动画相对于物件的X坐标的开始位置//第五个参数pivotXType为动画在Y轴相对于物件位置类型 //第六个参数pivotYValue为动画相对于物件的Y坐标的开始位置animation_rotate.setRepeatCount(-1);animation_rotate.setStartOffset(0);animation_rotate.setDuration(1000);LinearInterpolator lir = new LinearInterpolator();animationSet.setInterpolator(lir);animationSet.addAnimation(animation_rotate);}
}
2.dialog_loading布局
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"android:id="@+id/ll_body"android:layout_width="wrap_content"android:layout_height="wrap_content"android:background="#00000000"android:orientation="horizontal"android:padding="10dp"><RelativeLayoutandroid:layout_width="wrap_content"android:layout_height="wrap_content"><!-- <ImageView-->
<!-- android:layout_width="wrap_content"-->
<!-- android:layout_height="wrap_content"-->
<!-- android:layout_centerInParent="true"-->
<!-- android:src="@drawable/ic_loading_ing" />--><!-- <ImageView-->
<!-- android:layout_width="50dp"-->
<!-- android:layout_height="50dp"-->
<!-- android:layout_centerInParent="true"-->
<!-- android:src="@drawable/ic_loading_logo" />--><ImageViewandroid:id="@+id/iv_ing"android:layout_width="60dp"android:layout_height="60dp"android:layout_centerInParent="true"android:src="@drawable/ic_loading" /><TextViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:text="正在加载中..."android:layout_below="@+id/iv_ing"android:layout_marginTop="20dp"/></RelativeLayout>
</LinearLayout>
3.调用
LoadingDialog.getInstance(this).show();//显示LoadingDialog.getInstance(context).hide();//隐藏销毁当前页面后
LoadingDialog.setInstance(null);//设置为空 然会报错
加载图片
Android Loading加载动画相关推荐
- android 载入svg动画,实例讲解使用SVG制作loading加载动画的方法
今天和大家分享一个以SVG图像为主的loading加载动画,现在移动端网页使用比较多,若还用GIF做loading图片的话,可能会影响图像的质量,所以使用SVG是一个不错的方式. 这次展示的代码由 A ...
- 2款不同样式的CSS3 Loading加载动画 附源码
原文:2款不同样式的CSS3 Loading加载动画 附源码 我们经常看到的Loading加载很多都是转圈圈的那种,今天我们来换一种有创意的CSS3 Loading加载动画,一种是声波形状的动画,另一 ...
- html5 css3炫酷效果,28种纯CSS3炫酷loading加载动画特效
这是一组效果非常炫酷的纯CSS3 Loading加载动画特效.这组loading动画共有27种不同的效果.每一种loading动画都是通过CSS3的keyframes帧动画来完成的,每一个加载动画都构 ...
- CSS - 实现Loading加载动画
Loading加载动画 用CSS都用实现一个loading的加载动画 通过控制 item-loader-container 来实现显示及隐藏 <div class="item-load ...
- html加载特效大全,10种炫酷的CSS3 loading加载动画特效
这是一组效果非常炫酷的纯CSS3 loading加载动画特效.这组loading动画共10种不同的效果,全部使用animation帧动画制作而成.这些特效代码简洁,效果炫酷,非常值得学习借鉴. 制作方 ...
- Css3+jquery 实现loading加载动画
一.Css3+jquery 实现loading加载动画 这是一个 Loading 加载demo 不需要图片 纯html和css 实现样式 以下是html css以及js的代码 需要自取 <!DO ...
- 【web前端特效源码】使用HTML5+CSS3制作一个会动的音频loading加载动画效果~~适合初学者~超简单~ |前端开发|IT编程
b站视频演示效果: [web前端特效源码]使用HTML5+CSS3制作一个会动的音频loading加载动画效果~~适合初学者~超简单~ |前端开发|IT软件 效果图: 完整代码: <!DOCTY ...
- Vue在请求(axios)里面实现loading加载动画
1.在main.js里引入axios import axios from "@/http/index.js" 2.在vuex中设置状态 state: {isLoading: fal ...
- 150款+炫酷的CSS3 loading加载动画,总有一款适合你
是不是非常有趣? 最后,附上150款+CSS3 loading加载动画的下载地址: 下载地址: https://pan.baidu.com/s/1upupoPpI0KDrK1lk_m4MmA 提取码: ...
最新文章
- VC中基于 Windows 的精确定时
- Android开源项目
- 【转载】dos下通过wmic命令查看硬盘和内存/CPU信息(windows自带命令查看硬件信息)
- Hibernate锁定模式– OPTIMISTIC_FORCE_INCREMENT锁定模式如何工作
- python环绕文字_如何用css实现文字三面环绕图片?
- css怎样设置li分栏,css怎么对文字分栏
- 为什么大家更愿意使用MyBatis,读完源码我知道了…
- 管理者和领导者的区别_如何赢得领导者的尊重
- php 类 private,有关php类的private属性继承问题详解
- 【转】Update: Android.mk 中的 LOCAL_SRC_FILES, LOCAL_C_INCLUDES
- java属性定义_Kotlin 真香系列:扩展函数和属性
- android让文本输入框默认不获取焦点,android EditText 默认情况下不获取焦点(不弹出输入框)...
- STC8H8K系列汇编51实战——STC8H8K64U跑马灯(51版)
- 桌面图标有阴影的解决方法
- python一入深似海-模块化编程-钢铁侠战甲(二)
- Science复活远古“蛋白质”,揭示光合作用的“昨天、今天和明天”
- 基于爬虫爬取的数据,完成数据展示网站
- 你用过的论文写作神工具有哪些?
- C# 开发备忘录(自定义日历)
- 6-4 输出月份英文名 (15分)