2013-03-22 70 views
2

我遇到了一個奇怪的問題。在我的應用程序中,我有一個自定義SeekBar與拇指有2個狀態。當我點擊seekBar時,它的拇指會變形,幾秒鐘後恢復正常狀態。對象MediaPlayer對象立即作出反應,問題只是一個視覺問題。快照來說明這一點:seekBar拇指在seekBar被點擊時被拉伸

正常行爲:

enter image description here

當點擊seekBar

enter image description here

我不知道什麼是錯了。

搜索欄:

 <SeekBar 
     android:id="@+id/seekBarMain" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignParentBottom="true" 
     android:layout_alignParentLeft="true" 
     android:layout_gravity="bottom" 
     android:layout_marginBottom="5dp" 
     android:indeterminate="false" 
     android:maxHeight="3dp" 
     android:maxWidth="450dp" 
     android:minHeight="3dp" 
     android:paddingLeft="9dp" 
     android:paddingRight="9dp" 
     android:progressDrawable="@drawable/pb" 
     android:thumb="@drawable/thumb_state" /> 

可繪製用於大拇指:

 <?xml version="1.0" encoding="utf-8"?> 
     <selector xmlns:android="http://schemas.android.com/apk/res/android"> 

<item android:drawable="@drawable/thumb_pressed" android:state_enabled="true" android:state_pressed="true"/> 
<item android:drawable="@drawable/thumb" android:state_pressed="false"/> 

     </selector> 

OnTouchListener:

 @Override 
public boolean onTouch(View v, MotionEvent event) { 

    if (v.getId() == R.id.seekBarMain) { 

     if (mp.isPlaying()) { 

      int playPositionInMillisecconds = (mediaFileLengthInMilliseconds/100) 
        * sb.getProgress(); 
      mp.seekTo(playPositionInMillisecconds); 
     } else { 
      int playPositionInMillisecconds = (mediaFileLengthInMilliseconds/100) 
        * sb.getProgress(); 
      mp.start(); 
      mp.seekTo(playPositionInMillisecconds); 
      btnPlay.setBackgroundResource(R.drawable.button_pause); 
      primarySeekBarProgressUpdater(); 

     } 
    } 

    return false; 

} 

任何想法,爲什麼出現這種情況?

+0

我喜歡這種風格。你介意分享嗎? – Si8 2013-12-25 18:05:10

+1

@ SiKni8當然。我已經壓縮了相關資源,你可以在這裏下載它們(鏈接將被激活5天)http://files.mail.ru/38B5C7AFF63E4B9DBC942B43536AFE61讓我知道如果我忘記了一些東西 – Droidman 2013-12-25 19:36:20

+0

令人驚歎...謝謝:)我真的欣賞它。 – Si8 2013-12-26 00:18:03

回答

2

好的,我剛纔發現這個問題與"thumb_pressed" drawable有關,比可用於正常狀態的drawable大了25%左右。我無法真正解釋這一點,但修改"thumb_pressed" drawable與"thumb" drawable具有相同的大小解決了問題。