进度条SeekBar

SeekBar:

A SeekBar is an extension of ProgressBar that adds a draggable thumb. The user can touch the thumb and drag left or right to set the current progress level or use the arrow keys. Placing focusable widgets to the left or right of a SeekBar is discouraged.

意思是:SeekBar是进度条的一个扩展,可以通过手动调节当前进度。将焦点放在进度条的最左边或右边是不允许的。

建立布局编码:

<!--进度条,显示当前歌曲播放时间-->
    <SeekBar android:id="@+id/seekbar"
        android:layout_width="230dp"
        android:layout_height="13dp"
        android:layout_below="@id/btStop"
        android:layout_centerInParent="true"
        android:progressDrawable="@drawable/seekbar_style"
        android:thumb="@drawable/thumb"
        android:paddingRight="0dp"
        android:paddingLeft="0dp"
        android:progress="0"
        android:max="100"
        />

效果图:



首先与所播放的多媒体建立联系:

//实现音轨监听器处理操作
    private SeekBar.OnSeekBarChangeListener seekBarListener = new SeekBar.OnSeekBarChangeListener() {
        @Override
        public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
            if (fromUser) {//关键在这与mplayer通过seekTo建立联系
                mplayer.seekTo(progress);//Seeks to specified time position.
                //msec - the offset in milliseconds from the start to seek to
                currently_Time.setText(getFileTime(progress));
            }
        }

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {

        }

        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {

        }
    };

进一步操作-控制焦点的进度:

private Runnable thread = new Runnable() {
        public void run() {
            //Get the progress bar's current level of progress. Return 0 when the
            //progress bar is in indeterminate mode.
            seekBar.setProgress(mplayer.getCurrentPosition());//进度条的焦点图片移动起来
            if(mplayer.getCurrentPosition()>=mplayer.getDuration()){
                seekBar.setProgress(0);
                currently_Time.setText("00:00");
            }else
            currently_Time.setText(getFileTime(mplayer.getCurrentPosition()));
           
            handler.postDelayed(thread_One, 1000);//Go to thread_One every other one second.
        }
    };


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值