总结下开发中常用的几类自定义加载旋转框
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>