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

想實(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ú)立出來(lái)作為一個(gè)XML文件,在Android中如果要在布局文件中引入其他布局文件時(shí),方法其實(shí)和JSP編程中的Include十分相似哈,具體的格式如下:<include android:id="@+id/layout_process" layout="@layout/processbar" />
下面我們就來(lái)說(shuō)說(shuō)要怎么實(shí)現(xiàn)旋轉(zhuǎn)進(jìn)程的實(shí)現(xiàn),由于自帶的加載樣式不好看,我們就需要自定義樣式,這時(shí)候需要一張png圖片,即旋轉(zhuǎn)的進(jìn)度條。
接下來(lái)我們需要定義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)然還沒(méi)實(shí)現(xiàn)上面的效果,當(dāng)然我們還要的就是讓圖片動(dòng)起來(lái),那么我們就需要自定義的屬性動(dòng)畫(huà)哈,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ú)立出來(lái)作為一個(gè)XML文件,在Android中如果要在布局文件中引入其他布局文件時(shí),方法其實(shí)和JSP編程中的Include十分相似哈,具體的格式如下:<include android:id="@+id/layout_process" layout="@layout/processbar" />
下面我們就來(lái)說(shuō)說(shuō)要怎么實(shí)現(xiàn)旋轉(zhuǎn)進(jìn)程的實(shí)現(xiàn),由于自帶的加載樣式不好看,我們就需要自定義樣式,這時(shí)候需要一張png圖片,即旋轉(zhuǎn)的進(jìn)度條。
接下來(lái)我們需要定義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)然還沒(méi)實(shí)現(xiàn)上面的效果,當(dāng)然我們還要的就是讓圖片動(dòng)起來(lái),那么我們就需要自定義的屬性動(dòng)畫(huà)哈,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ù)、閃爍問(wèn)題分析及解決方案
- Android加載大分辨率圖片到手機(jī)內(nèi)存中的實(shí)例方法
- Android使用控件ImageView加載圖片的方法
- Android關(guān)于Glide的使用(高斯模糊、加載監(jiān)聽(tīng)、圓角圖片)
- Android實(shí)現(xiàn)加載廣告圖片和倒計(jì)時(shí)的開(kāi)屏布局
- Android圖片加載利器之Picasso基本用法
- Android 異步加載圖片分析總結(jié)
- Android高效安全加載圖片的方法詳解
相關(guān)文章
詳細(xì)講解AsyncTask使用說(shuō)明(值得收藏)
AsyncTask就相當(dāng)于Android給我們提供了一個(gè)多線程編程的一個(gè)框架,其介于Thread和Handler之間,我們?nèi)绻x一個(gè)AsyncTask,就需要定義一個(gè)類(lèi)來(lái)繼承AsyncTask這個(gè)抽象類(lèi),并實(shí)現(xiàn)其唯一的一doInBackgroud 抽象方法,這篇文章主要介紹了AsyncTask詳解,需要的朋友可以參考下2024-01-01Android AlertDialog自定義樣式實(shí)現(xiàn)代碼
這篇文章主要介紹了Android AlertDialog自定義樣式實(shí)現(xiàn)代碼的相關(guān)資料,這里提供了實(shí)例代碼,一個(gè)簡(jiǎn)單示例,需要的朋友可以參考下2016-12-12Flutter開(kāi)發(fā)Mac桌面應(yīng)用實(shí)現(xiàn)自動(dòng)提取生成視頻字幕文件
這篇文章主要為大家介紹了Flutter開(kāi)發(fā)Mac桌面應(yīng)用實(shí)現(xiàn)自動(dòng)提取生成視頻字幕文件示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-03-03Android編程動(dòng)態(tài)按鈕實(shí)現(xiàn)方法
這篇文章主要介紹了Android編程動(dòng)態(tài)按鈕實(shí)現(xiàn)方法,分享了onTouch方法及xml調(diào)用兩種實(shí)現(xiàn)技巧,需要的朋友可以參考下2016-10-10深入解析Android中的setContentView加載布局原理
在日常開(kāi)發(fā)Android中setContentView是必不可少的一部分,下面這篇文章主要給大家介紹了關(guān)于Android中setContentView的相關(guān)資料,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)下吧。2017-09-09Android通過(guò)BLE傳輸文件遇到問(wèn)題解決
這篇文章主要為大家介紹了Android通過(guò)BLE傳輸文件遇到問(wèn)題解決方法,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-04-04Android自定義button點(diǎn)擊效果的兩種方式
這篇文章主要為大家詳細(xì)介紹了Android自定義button點(diǎn)擊效果的兩種方式,感興趣的小伙伴們可以參考一下2016-05-05