android自定义加载旋转框

总结下开发中常用的几类自定义加载旋转框

1.贴图,看看第一种加载旋转框

这里写图片描述

  • 在ios开发中,都会经常看到类似的加载旋转框,而android的加载旋转框就各式各样

    实现:

    • 1.创建res/anim/rotate_loading.xml文件

          <?xml version="1.0" encoding="utf-8"?>
          <set android:shareInterpolator="false"
              xmlns:android="http://schemas.android.com/apk/res/android">
              <rotate
                  android:interpolator="@android:anim/linear_interpolator"
                  android:pivotX="50%"        
                  android:pivotY="50%"
                  android:fromDegrees="0"
                  android:toDegrees="+360"
                  android:duration="1100"
                  android:startOffset="-1"            //设置动画执行之前的时间
                  android:repeatMode="restart"
                  android:repeatCount="-1" />         //设置动画重复执行的次数
          </set>
      
    • 2.在xml布局敲如下代码

          <RelativeLayout xmlns: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"
               tools:context="com.hy.progress.MainActivity" >
      
                 <ImageView
                          android:id="@+id/progress_bar"
                          android:layout_width="wrap_content"
                          android:layout_height="wrap_content"
                          android:scaleType="center"
                          android:layout_centerInParent="true"
                          android:src="@drawable/progress_icon"/>
                  <TextView
                      android:layout_width="wrap_content"
                      android:layout_height="wrap_content"
                      android:layout_marginLeft="8dip"
                      android:layout_below="@id/progress_bar"
                      android:layout_centerInParent="true"
                      android:text="相册初始化中..."
                      android:textColor="#666666"
                      android:textSize="16sp" />
      
          </RelativeLayout>
      
    • 3.在代码中敲如下代码

      ImageView ivProgress = (ImageView) findViewById(R.id.progress_bar);
      Animation loadAnimation = AnimationUtils.loadAnimation(this,R.anim.rotate_loading);
      ivProgress.startAnimation(loadAnimation);

综上,就完成了第一种加载旋转框
2.贴图,看看第二种加载旋转框

这里写图片描述

  • 有人说这种加载旋转框挺丑的,不管丑不丑,你能实现了再来评论丑不丑

    实现:

    • 1.创建res/anim/rotate_loading.xml文件

      <?xml version="1.0" encoding="utf-8"?>
          <rotate xmlns:android="http://schemas.android.com/apk/res/android"
              android:pivotX="50%" android:pivotY="50%"
              android:fromDegrees="0"
              android:toDegrees="360">
      
              <shape
                  android:shape="ring"
                  android:innerRadiusRatio="3"
                  android:thicknessRatio="8"
                  android:useLevel="false">
      
                  <gradient
                      android:type="sweep"
                      android:useLevel="false"
                      android:startColor="#f4e10d"
                      android:centerColor="#ff6b21"
                      android:centerY="0.50"
                      android:endColor="#00bf8f" />    
              </shape>
      
          </rotate>
      
    • 2.在xml布局敲如下代码

      <RelativeLayout xmlns: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"
          tools:context="com.hy.progress.MainActivity" >
      
          <ProgressBar
              android:id="@+id/loading_two"
              android:layout_width="60dp"
              android:layout_height="60dp"
              android:indeterminateDrawable="@anim/loading_two"
              android:layout_centerInParent="true"/>
           <TextView
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:layout_marginLeft="8dip"
              android:layout_below="@id/loading_two"
              android:layout_centerInParent="true"
              android:text="晴天初始化中..."
              android:textColor="#666666"
              android:textSize="16sp" />
      
      </RelativeLayout>
      
综上,就完成了第二种加载旋转框
3.贴图,看看第三种加载旋转框

这里写图片描述

  • 黑白交替的旋转框,自我感觉跟白色背景混搭不怎么好看!

    实现:

    • 1.创建res/anim/rotate_loading.xml文件

          <?xml version="1.0" encoding="utf-8"?>
          <layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
      
                <item>
                   <rotate
                      android:fromDegrees="0"
                      android:toDegrees="360"
                      android:pivotX="50%"
                      android:pivotY="50%"
                      android:drawable="@drawable/yh_spinner_big_inner"/>
                </item>
      
                <item>
                   <rotate
                      android:fromDegrees="360"
                      android:toDegrees="0"
                      android:pivotX="50%"
                      android:pivotY="50%"
                      android:drawable="@drawable/yh_spinner_big_outer"/>
                </item>
      
          </layer-list>
      
    • 2.在xml布局敲如下代码

          <RelativeLayout xmlns: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"
              android:background="#55000000"
              tools:context="com.hy.progress.MainActivity" >
      
              <ProgressBar
                  android:id="@+id/loading_two"
                  android:layout_width="80dp"
                  android:layout_height="80dp"
                  android:indeterminateDrawable="@drawable/rotate_three"
                  android:layout_centerInParent="true"/>
               <TextView
                  android:layout_below="@id/loading_two"
                  android:layout_width="wrap_content"
                  android:layout_height="wrap_content"
                  android:layout_marginLeft="8dp"
                  android:layout_centerInParent="true"
                  android:text="美女初始化中..."
                  android:textColor="#ff0000"
                  android:textSize="18sp" />
      
          </RelativeLayout>
      
综上,就完成了第三种加载旋转框

——坚持养成整理资料的习惯——-资料整理中——-

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值