Android 基本控制項 之 SeekBar(一) 個性你的視圖

來源:互聯網
上載者:User

系統內建的SeekBar組件的樣式較為老土,已經不能滿足廣大開發人員的需求了,這裡給大家介紹一個簡單快捷的定製自己的SeekBar樣式的方法,不必重寫哦!   1.準備幾張個人化的圖片,一張是拖動條背景圖,一張是進度條圖,一張是拖動條圖。    這裡給幾張示範圖: 

   :拖動條背景圖


  :進度條圖
 
  :拖動條圖
 

   2.在res/drawable 目錄下建立一個xml檔案 ,配置資訊如下:  seekbar_progress.xml[html]  <?xml version="1.0" encoding="utf-8"?>  <layer-list    xmlns:android="http://schemas.android.com/apk/res/android">      <item android:id="@android:id/background"> // 背景項          <nine-patch android:src="@drawable/progress_background" /> // 背景圖 // 這裡使用9檔案,因此這麼配置如果使用的是普通圖片可直接使用<drawable />標籤,或者使用<shape />標籤,自訂圖形      </item>      <item android:id="@android:id/progress"> // 進度項          <clip>              <nine-patch android:src="@drawable/progress_progress" /> // 進度圖          </clip>      </item>  </layer-list>   3.接下來<SeekBar ...        />標籤中添加如下參數: [html]   www.2cto.comandroid:progressDrawable="@drawable/seekbar_progress"  android:thumb="@drawable/thumb_drawable"  好了,經過上面的三個步驟,就可以輕鬆的實現自訂的SeekBar視圖了。看下效果吧!     附:這裡再貼一個使用<shape  />標籤為SeekBar設定背景和進度的xml設定檔,注意和上面的使用9檔案的比對:[html] <?xml version="1.0" encoding="utf-8"?>  <!-- ChenJianLi Code: View: Seekbar           滑動時的背景效果 -->    <layer-list xmlns:android="http://schemas.android.com/apk/res/android">    <!--  背景  -->      <item android:id="@android:id/background">          <shape>              <corners android:radius="5dip" />              <gradient                      android:startColor="#ffffffff"                      android:centerColor="#fffffff0"                      android:centerY="0.75"                      android:endColor="#fffffafa"                      android:angle="270"              />          </shape>      </item>      <!--  第二進度條  -->      <item android:id="@android:id/secondaryProgress">          <clip>              <shape>                  <corners android:radius="5dip" />                  <gradient                          android:startColor="#8000cdcd"                          android:centerColor="#8000bfff"                          android:centerY="0.75"                          android:endColor="#a000b2ee"                          android:angle="270"                  />              </shape>          </clip>      </item>      <!--  第一進度條  -->      <item android:id="@android:id/progress">          <clip>              <shape>                  <corners android:radius="5dip" />                  <gradient                          android:startColor="#ff00ffff"                          android:centerColor="#ff00ced1"                          android:centerY="0.75"                          android:endColor="#ff00f5ff"                          android:angle="270"                  />              </shape>          </clip>      </item>        </layer-list>    

聯繫我們

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