Android中自定義加載樣式圖片的具體實(shí)現(xiàn)
更新時(shí)間:2014年04月10日 16:43:05 作者:
想實(shí)現(xiàn)下面這張圖中的自定義加載樣式,其實(shí)很簡(jiǎn)單,首先我們需要的布局組件有ProcessBar和TextView,下面是布局文件的代碼
先讓大家看看效果圖吧,相信很多Android初學(xué)者都想知道這中效果是怎么實(shí)現(xiàn)的,來上圖:

想實(shí)現(xiàn)上面這張圖中的自定義加載樣式,其實(shí)很簡(jiǎn)單,首先我們需要的布局組件有ProcessBar和TextView,下面是布局文件的代碼(只是加載的頁(yè)面的布局):
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:gravity="center">
<ProgressBar
android:id="@+id/progressBar1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="@style/process_bar_style"/>
<TextView
android:id="@+id/processhint"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:text="@string/prohint"
android:textSize="18sp" />
</LinearLayout>
因?yàn)檫@個(gè)頁(yè)面的使用平率很高,所以我們把它單獨(dú)獨(dú)立出來作為一個(gè)XML文件,在Android中如果要在布局文件中引入其他布局文件時(shí),方法其實(shí)和JSP編程中的Include十分相似哈,具體的格式如下:<include android:id="@+id/layout_process" layout="@layout/processbar" />
下面我們就來說說要怎么實(shí)現(xiàn)旋轉(zhuǎn)進(jìn)程的實(shí)現(xiàn),由于自帶的加載樣式不好看,我們就需要自定義樣式,這時(shí)候需要一張png圖片,即旋轉(zhuǎn)的進(jìn)度條。
接下來我們需要定義style文件。process_style.xml(定義在values文件夾下)
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<style name="process_bar_style">
<item name="android:indeterminateDrawable">@drawable/processstyle</item>
</style>
</resources>
定義完style文件后,當(dāng)然還沒實(shí)現(xiàn)上面的效果,當(dāng)然我們還要的就是讓圖片動(dòng)起來,那么我們就需要自定義的屬性動(dòng)畫哈,process.xml,在drawable文件夾下定義
<?xml version="1.0" encoding="utf-8"?>
<animated-rotate xmlns:android="http://schemas.android.com/apk/res/android"
android:drawable="@drawable/process"
android:pivotX="50%"
android:pivotY="50%"
/>
關(guān)鍵的就是這個(gè)代碼,可以實(shí)現(xiàn)圖片的自動(dòng)旋轉(zhuǎn)。
那么大家可以嘗試下了哈,自己也能做加載的設(shè)計(jì)者

想實(shí)現(xiàn)上面這張圖中的自定義加載樣式,其實(shí)很簡(jiǎn)單,首先我們需要的布局組件有ProcessBar和TextView,下面是布局文件的代碼(只是加載的頁(yè)面的布局):
復(fù)制代碼 代碼如下:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:gravity="center">
<ProgressBar
android:id="@+id/progressBar1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="@style/process_bar_style"/>
<TextView
android:id="@+id/processhint"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:text="@string/prohint"
android:textSize="18sp" />
</LinearLayout>
因?yàn)檫@個(gè)頁(yè)面的使用平率很高,所以我們把它單獨(dú)獨(dú)立出來作為一個(gè)XML文件,在Android中如果要在布局文件中引入其他布局文件時(shí),方法其實(shí)和JSP編程中的Include十分相似哈,具體的格式如下:<include android:id="@+id/layout_process" layout="@layout/processbar" />
下面我們就來說說要怎么實(shí)現(xiàn)旋轉(zhuǎn)進(jìn)程的實(shí)現(xiàn),由于自帶的加載樣式不好看,我們就需要自定義樣式,這時(shí)候需要一張png圖片,即旋轉(zhuǎn)的進(jìn)度條。
接下來我們需要定義style文件。process_style.xml(定義在values文件夾下)
復(fù)制代碼 代碼如下:
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<style name="process_bar_style">
<item name="android:indeterminateDrawable">@drawable/processstyle</item>
</style>
</resources>
定義完style文件后,當(dāng)然還沒實(shí)現(xiàn)上面的效果,當(dāng)然我們還要的就是讓圖片動(dòng)起來,那么我們就需要自定義的屬性動(dòng)畫哈,process.xml,在drawable文件夾下定義
復(fù)制代碼 代碼如下:
<?xml version="1.0" encoding="utf-8"?>
<animated-rotate xmlns:android="http://schemas.android.com/apk/res/android"
android:drawable="@drawable/process"
android:pivotX="50%"
android:pivotY="50%"
/>
關(guān)鍵的就是這個(gè)代碼,可以實(shí)現(xiàn)圖片的自動(dòng)旋轉(zhuǎn)。
那么大家可以嘗試下了哈,自己也能做加載的設(shè)計(jì)者
您可能感興趣的文章:
- Android中Glide加載庫(kù)的圖片緩存配置究極指南
- android異步加載圖片并緩存到本地實(shí)現(xiàn)方法
- Android中ListView異步加載圖片錯(cuò)位、重復(fù)、閃爍問題分析及解決方案
- Android加載大分辨率圖片到手機(jī)內(nèi)存中的實(shí)例方法
- Android使用控件ImageView加載圖片的方法
- Android關(guān)于Glide的使用(高斯模糊、加載監(jiān)聽、圓角圖片)
- Android實(shí)現(xiàn)加載廣告圖片和倒計(jì)時(shí)的開屏布局
- Android圖片加載利器之Picasso基本用法
- Android 異步加載圖片分析總結(jié)
- Android高效安全加載圖片的方法詳解
相關(guān)文章
Flutter開發(fā)技巧RadialGradient中radius計(jì)算詳解
這篇文章主要為大家介紹了Flutter小技巧RadialGradient?中?radius?的計(jì)算詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-01-01
Android垂直滾動(dòng)控件ScrollView使用方法詳解
這篇文章主要為大家詳細(xì)介紹了Android垂直滾動(dòng)控件ScrollView的使用方法,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-08-08
Android-Service實(shí)現(xiàn)手機(jī)壁紙自動(dòng)更換
這篇文章主要為大家詳細(xì)介紹了Android-Service實(shí)現(xiàn)手機(jī)壁紙自動(dòng)更換,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2018-11-11
Android用PopupWindow實(shí)現(xiàn)自定義Dailog
這篇文章主要為大家詳細(xì)介紹了Android用PopupWindow實(shí)現(xiàn)自定義Dailog的相關(guān)資料,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-01-01
Android HorizontalScrollView滑動(dòng)與ViewPager切換案例詳解
這篇文章主要介紹了Android HorizontalScrollView滑動(dòng)與ViewPager切換案例詳解,本篇文章通過簡(jiǎn)要的案例,講解了該項(xiàng)技術(shù)的了解與使用,以下就是詳細(xì)內(nèi)容,需要的朋友可以參考下2021-08-08
Android TextView跑馬燈效果實(shí)現(xiàn)方法
這篇文章主要介紹了Android TextView跑馬燈效果實(shí)現(xiàn)方法,涉及Android布局文件中相關(guān)屬性的設(shè)置技巧,非常簡(jiǎn)單實(shí)用,需要的朋友可以參考下2016-01-01

