SeekBar的拇指只有在触摸时才会出现

我想要一个带有拇指的SeekBar ,当用户与它交互时(通过将其拖动到所需的位置)出现,并在交互后消失。

今天我的SeekBar看起来像这样:

<SeekBar android:id="@+id/seekBar_volume"
        android:layout_width="fill_parent"
        android:progressDrawable="@drawable/custom_player_seekbar_background"
        android:paddingTop="10px" 
        android:paddingBottom="10px" 
        android:thumb="@drawable/myThumb" 
        android:paddingLeft="30px" 
        android:paddingRight="30px" 
        android:minHeight="6dip"
        android:maxHeight="6dip" 
        android:layout_height="wrap_content"
        android:layout_centerVertical="true"/>

拇指位置仅随用户交互而改变(如“音量控制”)。

seekBarVolume.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {

        public void onStopTrackingTouch(SeekBar arg0) {

        }

        public void onStartTrackingTouch(SeekBar arg0) {

        }

        public void onProgressChanged(SeekBar arg0, int arg1, boolean arg2) {
           audioManager.setStreamVolume(AudioManager.STREAM_MUSIC, arg1, 0);
        }
});

我试图使用selector的功能,用定制的xml设置拇指的drawable来处理我想要的不同状态,但它不起作用= /

预先感谢您的帮助


感谢罗曼盖伊和一些错误修复,它完美地工作...

seekBarVolume.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {

    public void onStopTrackingTouch(SeekBar arg0) {
        // TODO Auto-generated method stub
        seekBarVolume.setThumb(null);
    }

    public void onStartTrackingTouch(SeekBar arg0) {
        seekBarVolume.setProgress(0);

        drawable = getResources().getDrawable(R.drawable.bt_do_player);
        final int quarterHeight = drawable.getIntrinsicHeight()/4;
        final int halfWidht = drawable.getIntrinsicWidth()/2;

        drawable.setBounds(new Rect(-halfWidht,
                -quarterHeight,
                halfWidht,
                3*quarterHeight));
        seekBarVolume.setThumb(drawable);

        seekBarVolume.setProgress(audioManager.getStreamVolume(AudioManager.STREAM_MUSIC));


    }

     public void onProgressChanged(SeekBar arg0, int arg1, boolean arg2) {
         audioManager.setStreamVolume(AudioManager.STREAM_MUSIC, arg1, 0);
     }
});
链接地址: http://www.djcxy.com/p/64333.html

上一篇: SeekBar's thumb only appears when touched

下一篇: Why doesn't ICollection<T> implement ICollection?