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

想實現(xiàn)上面這張圖中的自定義加載樣式,其實很簡單,首先我們需要的布局組件有ProcessBar和TextView,下面是布局文件的代碼(只是加載的頁面的布局):
<?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>
因為這個頁面的使用平率很高,所以我們把它單獨獨立出來作為一個XML文件,在Android中如果要在布局文件中引入其他布局文件時,方法其實和JSP編程中的Include十分相似哈,具體的格式如下:<include android:id="@+id/layout_process" layout="@layout/processbar" />
下面我們就來說說要怎么實現(xiàn)旋轉(zhuǎn)進程的實現(xiàn),由于自帶的加載樣式不好看,我們就需要自定義樣式,這時候需要一張png圖片,即旋轉(zhuǎ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文件后,當然還沒實現(xiàn)上面的效果,當然我們還要的就是讓圖片動起來,那么我們就需要自定義的屬性動畫哈,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)鍵的就是這個代碼,可以實現(xiàn)圖片的自動旋轉(zhuǎn)。
那么大家可以嘗試下了哈,自己也能做加載的設(shè)計者

想實現(xiàn)上面這張圖中的自定義加載樣式,其實很簡單,首先我們需要的布局組件有ProcessBar和TextView,下面是布局文件的代碼(只是加載的頁面的布局):
復(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>
因為這個頁面的使用平率很高,所以我們把它單獨獨立出來作為一個XML文件,在Android中如果要在布局文件中引入其他布局文件時,方法其實和JSP編程中的Include十分相似哈,具體的格式如下:<include android:id="@+id/layout_process" layout="@layout/processbar" />
下面我們就來說說要怎么實現(xiàn)旋轉(zhuǎn)進程的實現(xiàn),由于自帶的加載樣式不好看,我們就需要自定義樣式,這時候需要一張png圖片,即旋轉(zhuǎ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文件后,當然還沒實現(xiàn)上面的效果,當然我們還要的就是讓圖片動起來,那么我們就需要自定義的屬性動畫哈,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)鍵的就是這個代碼,可以實現(xiàn)圖片的自動旋轉(zhuǎn)。
那么大家可以嘗試下了哈,自己也能做加載的設(shè)計者
您可能感興趣的文章:
- Android中Glide加載庫的圖片緩存配置究極指南
- android異步加載圖片并緩存到本地實現(xiàn)方法
- Android中ListView異步加載圖片錯位、重復(fù)、閃爍問題分析及解決方案
- Android加載大分辨率圖片到手機內(nèi)存中的實例方法
- Android使用控件ImageView加載圖片的方法
- Android關(guān)于Glide的使用(高斯模糊、加載監(jiān)聽、圓角圖片)
- Android實現(xiàn)加載廣告圖片和倒計時的開屏布局
- Android圖片加載利器之Picasso基本用法
- Android 異步加載圖片分析總結(jié)
- Android高效安全加載圖片的方法詳解
相關(guān)文章
Android AlertDialog自定義樣式實現(xiàn)代碼
這篇文章主要介紹了Android AlertDialog自定義樣式實現(xiàn)代碼的相關(guān)資料,這里提供了實例代碼,一個簡單示例,需要的朋友可以參考下2016-12-12
Flutter開發(fā)Mac桌面應(yīng)用實現(xiàn)自動提取生成視頻字幕文件
這篇文章主要為大家介紹了Flutter開發(fā)Mac桌面應(yīng)用實現(xiàn)自動提取生成視頻字幕文件示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪2023-03-03
深入解析Android中的setContentView加載布局原理
在日常開發(fā)Android中setContentView是必不可少的一部分,下面這篇文章主要給大家介紹了關(guān)于Android中setContentView的相關(guān)資料,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)下吧。2017-09-09

