进度条SeekBar

来源:互联网 发布:今日非农数据结果 编辑:程序博客网 时间:2024/05/16 10:29

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


0 0
原创粉丝点击