Android SeekBar的使用

來源:互聯網
上載者:User

Google提供了SeekBar控制項,可以非常方便的製作抽屜效果,但起初使用該控制項還是碰到不少問題,因此記錄如下:

其中兩個屬性比較重要:

progressDrawable: 表示SeekBar的背景色;thumb 表示滑動的圖片。

有兩點需要注意:

1、通常設定thumb後,滑動圖片會被隱藏一部分。設定thumbOffset就可以解決該問題

 

android:thumbOffset="0dp"

 

2、需要修改滑動SeekBar過程中的填充顏色,需要建立一個drawable檔案,

如名為seekbar_style.xml 具體代碼如下?

 

<layer-list xmlns:android="http://schemas.android.com/apk/res/android"><item android:id="@android:id/background"><shape><corners android:radius="10dip" /><gradient android:startColor="#ffffffff"android:centerColor="#ffffffff" android:endColor="#ffffffff"android:centerY="0.45" android:angle="270" /></shape></item><item android:id="@android:id/progress"><clip><shape><corners android:radius="10dip" /><gradient android:startColor="#FF75BC32"android:centerColor="#FF75BC32" android:endColor="#FF75BC32"android:centerY="0.45" android:angle="270" /></shape></clip></item></layer-list>

background設定的是SeekBar的預設背景顏色; progress 設定的是滑動過程中填充的顏色。

4、設定滑動杆粗細,設定maxHeight和minHeight為同一值即可,如

 android:maxHeight="4dp" android:minHeight="4dp"

 

完整的SeekBar樣式代碼如下:

 
<SeekBar            android:layout_marginLeft="25dp"            android:thumb="@drawable/progress_bar_button"            android:layout_width="327dp"            android:layout_height="18dp"            android:thumbOffset="0dp"            android:maxHeight="4dp"            android:minHeight="4dp"            android:progressDrawable="@drawable/seekbar_style"            android:id="@+id/seekBarVolume"></SeekBar>

如下:

ImageButton設定圖片方式,有以下三種:

 

setImageBitmap(Bitmap bm) setImageDrawable(Drawable drawable) setImageResource(int resId)

 

 

設定透明背景可以通過設定background完成

android:background="#00000000"即可

半透明 

android:background="#7F000000"即可。

聯繫我們

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