簡單自訂拖動條

來源:互聯網
上載者:User

開發音樂播放器要一個拖動條顯示播放位置, 系統那個拖動條大了根本不能用。

 

 

android:minHeight="2pt"
  android:maxHeight="2pt"
只把那個拖動條高度改變了, 那個拖動按鈕一樣的東西死都不變小。 網上說可以自訂的。直接重畫那個Thumb。
xml代碼
 

<?xml version="1.0" encoding="UTF-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android">     <!-- 按下狀態-->     <item android:state_focused="true" android:state_pressed="true"  >        <shape android:shape="oval">             <gradient android:type="radial" android:gradientRadius="8"                 android:angle="0" android:startColor="#FFFF0000"                 android:centerColor="#FF00FF00" android:endColor="#000000" />             <size android:width="16dip" android:height="100dip"></size>         </shape>            </item> </selector>

可是我就不明白那個item裡面的東西該如何定義。下午看了一個下午的源碼

    public SeekBar(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
    }

調用
 

public AbsSeekBar(Context context, AttributeSet attrs, int defStyle) {        super(context, attrs, defStyle);        TypedArray a = context.obtainStyledAttributes(attrs,                com.android.internal.R.styleable.SeekBar, defStyle, 0);        Drawable thumb = a.getDrawable(com.android.internal.R.styleable.SeekBar_thumb);        setThumb(thumb); // will guess mThumbOffset if thumb != null...        // ...but allow layout to override this        int thumbOffset = a.getDimensionPixelOffset(                com.android.internal.R.styleable.SeekBar_thumbOffset, getThumbOffset());        setThumbOffset(thumbOffset);        a.recycle();        a = context.obtainStyledAttributes(attrs,                com.android.internal.R.styleable.Theme, 0, 0);        mDisabledAlpha = a.getFloat(com.android.internal.R.styleable.Theme_disabledAlpha, 0.5f);        a.recycle();        mScaledTouchSlop = ViewConfiguration.get(context).getScaledTouchSlop();    }

調用父類的一個建構函式  在這裡面看的了
Drawable thumb = a.getDrawable(com.android.internal.R.styleable.SeekBar_thumb);
        setThumb(thumb); // will guess mThumbOffset if thumb != null...

看了drawable裡面的com.android.internal.R.styleable.SeekBar_thumb
 

<selector xmlns:android="http://schemas.android.com/apk/res/android">    <item android:state_pressed="true"          android:state_window_focused="true"          android:drawable="@drawable/seek_thumb_pressed" />    <item android:state_focused="true"          android:state_window_focused="true"          android:drawable="@drawable/seek_thumb_selected" />    <item android:state_selected="true"          android:state_window_focused="true"          android:drawable="@drawable/seek_thumb_selected" />    <item android:drawable="@drawable/seek_thumb_normal" /></selector>

檔案中@drawable/seek_thumb_normal這些讓我迷糊了 ,裡面的檔案對應到什麼地方呢, 在eclipse裡面找了
res裡面 雙擊 打不開。  當時就鬱悶了   明明是一個png檔案怎麼打不開呢 !弄了好久還以為是android系統檔案 但系統目錄下找到了一個system.img 檔案還以為源檔案在裡面  搗鼓了半天打不開,網上差說rar可以開啟  狗屁  是linux裡面檔案  暈了  差點就想把自己電腦給換系統
   本想放棄了,在回到eclipse裡面的時候再開啟 認真看了錯誤原因那段英文  說叫我去源檔案那邊開啟 在左下角看有個路徑  幹  android.jar
開啟檔案  終於找到了。就幾張圖片  搞了我半天
   那個拉動按鈕是引用這邊的圖片, 我馬上把圖片copy出來 自己直接改小
 在布局檔案中引用自己的圖片  運行調試  ok 
 

 

    <SeekBar
           android:id="@+id/musicSeek"
           style="@android:style/Widget.SeekBar"
           android:layout_width="fill_parent"
           android:layout_height="wrap_content"
           android:thumb="@drawable/seek_thumb_pressed"
           android:minHeight="2pt"
           android:maxHeight="2pt"
           android:paddingLeft="6pt"
           android:paddingRight="6pt"
           />
        
       

聯繫我們

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