自定义加载动画的两种实现方式

简介: 自定义加载动画的两种实现方式

1.帧动画 方式

动画文件animation.xml

<?xml version="1.0" encoding="utf-8"?>  
<animation-list  
  xmlns:android="http://schemas.android.com/apk/res/android"  
  android:oneshot="true">  
    <item android:drawable="@drawable/icon1" android:duration="150"></item>  
    <item android:drawable="@drawable/icon2" android:duration="150"></item>  
    <item android:drawable="@drawable/icon3" android:duration="150"></item>  
    <item android:drawable="@drawable/icon4" android:duration="150"></item>  
    <item android:drawable="@drawable/icon5" android:duration="150"></item>  
    <item android:drawable="@drawable/icon6" android:duration="150"></item>  
</animation-list>  

给imageView设置动画

    <ImageView android:id="@+id/animationIV"  
            android:layout_width="wrap_content"  
            android:layout_height="wrap_content"  
            android:padding="5px"  
            android:src="@drawable/animation"/>

2.progressbar方式

方式一

ProgressBar

<pre name="code" class="java"><ProgressBar  
           android:id="@+id/progressBar"  
           android:layout_width="wrap_content"  
           android:layout_height="wrap_content"  
           android:indeterminate="false"  
           android:indeterminateDrawable="@anim/progress_bar_loading" />  

动画 文件progressbar_bar_loading 放在values下的anim中

<?xml version="1.0" encoding="UTF-8"?>  
<animation-list  
    xmlns:android="http://schemas.android.com/apk/res/android"  
    android:oneshot="false">  
    <item  
       android:duration="250"  
       android:drawable="@drawable/progress_bar_loading_01" />  
    <item  
       android:duration="250"  
       android:drawable="@drawable/progress_bar_loading_02" />  
    <item  
       android:duration="250"  
       android:drawable="@drawable/progress_bar_loading_03" />  
    <item  
       android:duration="250"  
       android:drawable="@drawable/progress_bar_loading_04" />  
    <item  
       android:duration="250"  
       android:drawable="@drawable/progress_bar_loading_05" />  
    <item  
       android:duration="250"  
       android:drawable="@drawable/progress_bar_loading_06" />  
    <item  
       android:duration="250"  
       android:drawable="@drawable/progress_bar_loading_07" />  
</animation-list>  

方式二

<ProgressBar
                android:id="@+id/pull_to_refresh_progress"
                android:layout_width="30dip"
                android:layout_height="30dip"
                android:background="@drawable/all_refresh_logo"
                android:indeterminate="true"
                android:layout_gravity="center"
                android:indeterminateDrawable="@drawable/progress_top_refresh"/>

文件progress_top_refresh

<?xml version="1.0" encoding="utf-8"?>
<rotate xmlns:android="http://schemas.android.com/apk/res/android"
        android:drawable="@drawable/all_refresh"
        android:fromDegrees="0"
        android:pivotX="50%"
        android:pivotY="50%"
        android:toDegrees="360" />


相关文章
|
前端开发 Linux 程序员
「HTML+CSS」--自定义加载动画【028】
「HTML+CSS」--自定义加载动画【028】
213 0
「HTML+CSS」--自定义加载动画【028】
|
前端开发 Linux 程序员
「HTML+CSS」--自定义加载动画【012】
「HTML+CSS」--自定义加载动画【012】
61 0
「HTML+CSS」--自定义加载动画【012】
|
前端开发 Linux 程序员
「HTML+CSS」--自定义加载动画【017】
「HTML+CSS」--自定义加载动画【017】
65 0
「HTML+CSS」--自定义加载动画【017】
|
前端开发 Linux 程序员
「HTML+CSS」--自定义加载动画【016】
「HTML+CSS」--自定义加载动画【016】
68 0
「HTML+CSS」--自定义加载动画【016】
|
前端开发 Linux 程序员
「HTML+CSS」--自定义加载动画【025】
「HTML+CSS」--自定义加载动画【025】
55 0
「HTML+CSS」--自定义加载动画【025】
|
前端开发 Linux 程序员
「HTML+CSS」--自定义加载动画【018】
「HTML+CSS」--自定义加载动画【018】
99 0
「HTML+CSS」--自定义加载动画【018】
|
前端开发 Linux 程序员
「HTML+CSS」--自定义加载动画【027】
「HTML+CSS」--自定义加载动画【027】
107 0
「HTML+CSS」--自定义加载动画【027】
|
前端开发 Linux 程序员
「HTML+CSS」--自定义加载动画【011】
「HTML+CSS」--自定义加载动画【011】
99 0
「HTML+CSS」--自定义加载动画【011】
|
前端开发 Linux 程序员
「HTML+CSS」--自定义加载动画【019】
「HTML+CSS」--自定义加载动画【019】
84 0
「HTML+CSS」--自定义加载动画【019】
|
前端开发 Linux 程序员
「HTML+CSS」--自定义加载动画【026】
「HTML+CSS」--自定义加载动画【026】
66 0
「HTML+CSS」--自定义加载动画【026】