搜索栏的只有拇指触摸时出现 [英] SeekBar's thumb only appears when touched

查看:194
本文介绍了搜索栏的只有拇指触摸时出现的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想有一个搜索栏与在用户与它交互(通过拖动到所需的位置)和交互消失后出现了大拇指。

I want to have a SeekBar with a thumb that appears as the user interacts with it (by dragging it to the desired location) and disappears after the interaction.

今天我的搜索栏是这样的:

<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"/>

拇指位置只与用户交互(有点像音量控制)的变化。

The thumb position only changes with user interaction (something like a "volume control").

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);
        }
});

我试图用选择的功能,设置了拇指的绘制一个自定义的XML来处理不同的状态,我想,但它没有工作= /

I tried to use the selector's feature, setting the thumb's drawable with a customized xml to handle the different states I wanted, but it didn't work =/

在此先感谢您的帮助

推荐答案

感谢的罗曼盖伊,并修改了一些漏洞,它的工作完美...

Thanks to Romain Guy and some bug fixing, it worked perfectly...

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);
     }
});

这篇关于搜索栏的只有拇指触摸时出现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆