自訂圖片的progressbar

來源:互聯網
上載者:User

Android系統內建的Progressbar的樣式是固定的,當想使用自訂的進度條時,也很簡單

首先在布局檔案中加入進度條

  <ProgressBar        android:id="@+id/progressBar1"        style="?android:attr/progressBarStyleHorizontal"        android:layout_width="fill_parent"        android:progressDrawable="@drawable/progress"        android:layout_height="wrap_content"        android:layout_above="@+id/button1"        android:max="100"        android:visibility="visible"        android:layout_marginBottom="93dp" />

如果不實用progressDrawable標籤,這是系統預設的進度條,加入該標籤後則會使用自訂的drawable資源,這裡的progress就是自訂的xml檔案,放在drawable中

下面是其代碼

<?xml version="1.0" encoding="UTF-8"?><layer-list xmlns:android="http://schemas.android.com/apk/res/android"><!-- 定義軌道的背景 --><item android:id="@android:id/background"android:drawable="@drawable/grow" /><!-- 定義軌道上已完成部分的外觀--><item android:id="@android:id/progress"android:drawable="@drawable/ok" /></layer-list>     

這裡只是指定了進度條的顯示圖片,grow是一個圖片

如果想產生更加豐富的進度條樣式,可以修改上面這個代碼


聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.