Android?實現(xiàn)自定義圓形進度條的三種常用方法
Android 自定義 進度條,一般有三種方式,最早一般使用UI給的圖片使用幀動畫,完成,后面兩種,一種是使用自定義顏色,另外一種是使用帶相近色的圖片加動畫完成。
下面具體 說一下三種方式,推薦使用第二種方式,如果這種達不到效果,或者比較高也可使用第一種方式;
一、通過幀動畫實現(xiàn)
1.首先在res 下新建設(shè) anim 文件夾,在里面新建XML 文件;
定義res/anim/loading.xml如下:
例:loading.xml
<?xml version="1.0" encoding="UTF-8"?> <animation-list android:oneshot="false" xmlns:android="http://schemas.android.com/apk/res/android"> <item android:duration="150" android:drawable="@drawable/pic1" /> <item android:duration="150" android:drawable="@drawable/pic2" /> <item android:duration="150" android:drawable="@drawable/pic3" /> <item android:duration="150" android:drawable="@drawable/pic4" /> <item android:duration="150" android:drawable="@drawable/pic5" /> <item android:duration="150" android:drawable="@drawable/pic6" /> <item android:duration="150" android:drawable="@drawable/pic7" <item android:duration="150" android:drawable="@drawable/pic8"/> </animation-list>
二、通過自定義顏色實現(xiàn)
定義res/drawable/progress_color.xml如下:
<?xml version="1.0" encoding="utf-8"?> <rotate xmlns:android="http://schemas.android.com/apk/res/android" android:fromDegrees="0" android:pivotX="50%" android:pivotY="50%" android:toDegrees="360" > <shape android:innerRadiusRatio="3" android:shape="ring" android:thicknessRatio="8" android:useLevel="false" > <gradient android:centerColor="#FFDC35" android:centerY="0.50" android:endColor="#CE0000" android:startColor="#FFFFFF" android:type="sweep" android:useLevel="false" /> </shape> </rotate>
第三種 使用有進度的UI圖片:
定義res/drawable/progress_pic.xml如下:
<?xml version="1.0" encoding="utf-8"?> <rotate xmlns:android="http://schemas.android.com/apk/res/android" android:drawable="@drawable/progress1" android:fromDegrees="0" android:pivotX="50%" android:pivotY="50%" android:toDegrees="360" />
在Activity 布局中直接使用就可以:
<LinearLayout 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:orientation="vertical" tools:context="com.example.demo.MainActivity" > <ProgressBar android:id="@+id/loading_process_dialog_progressBar" android:layout_width="150dp" android:layout_height="150dp" android:layout_gravity="center_horizontal" android:indeterminate="false" android:indeterminateDrawable="@anim/loading" /> <ProgressBar style="?android:attr/progressBarStyleSmall" android:layout_width="100dp" android:layout_height="100dp" android:layout_marginTop="60dp" android:layout_gravity="center_horizontal" android:layout_centerInParent="true" android:indeterminateDrawable="@drawable/progress_small" /> <ProgressBar android:id="@+id/loading_process_pic" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_horizontal" android:layout_marginTop="60dp" android:indeterminate="false" android:indeterminateDrawable="@drawable/progress_pic" /> </LinearLayout>
到此這篇關(guān)于Android 實現(xiàn)自定義圓形進度條的三種常用方法的文章就介紹到這了,更多相關(guān)Android 實現(xiàn)自定義圓形進度條內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
Android自定義view實現(xiàn)太極效果實例代碼
這篇文章主要介紹了Android自定義view實現(xiàn)太極效果實例代碼的相關(guān)資料,需要的朋友可以參考下2017-05-05詳解Android?Flutter如何使用相機實現(xiàn)拍攝照片
在app中使用相機肯定是再平常不過的一項事情了,相機肯定涉及到了底層原生代碼的調(diào)用,那么在flutter中如何快速簡單的使用上相機的功能呢?一起來看看吧2023-04-04anroid開發(fā)教程之spinner下拉列表的使用示例
這篇文章主要介紹了anroid的spinner下拉列表的使用示例,需要的朋友可以參考下2014-04-04