Android中自訂載入樣式圖片的具體實現_Android

來源:互聯網
上載者:User
先讓大家看看效果圖吧,相信很多Android初學者都想知道這中效果是怎麼實現的,來上圖:

想實現上面這張圖中的自訂載入樣式,其實很簡單,首先我們需要的布局組件有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" />

下面我們就來說說要怎麼實現旋轉進程的實現,由於內建的載入樣式不好看,我們就需要自訂樣式,這時候需要一張png圖片,即旋轉的進度條。

接下來我們需要定義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檔案後,當然還沒實現上面的效果,當然我們還要的就是讓圖片動起來,那麼我們就需要自訂的屬性動畫哈,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%"
/>

關鍵的就是這個代碼,可以實現圖片的自動旋轉。

那麼大家可以嘗試下了哈,自己也能做載入的設計者

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.