布局文件参考
<LinearLayout
android:layout_width="120dp"
android:id="@+id/sb_parent_layout"
android:layout_height="25dp"
android:gravity="center_vertical">
<SeekBar
android:id="@+id/seek_bar"
android:layout_width="120dp"
android:layout_height="4dp"
android:progress="0"
android:progressDrawable="@drawable/bigun_seekbar_song"
android:thumb="@null" />
</LinearLayout>
代码文件
findViewById(R.id.sb_parent_layout).setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
Rect seekRect = new Rect();
mSeekBar.getHitRect(seekRect);
if ((event.getY() >= (seekRect.top - 500)) && (event.getY() <= (seekRect.bottom + 500))) {
float y = seekRect.top + seekRect.height() / 2;
//seekBar only accept relative x
float x = event.getX() - seekRect.left;
if (x < 0) {
x = 0;
} else if (x > seekRect.width()) {
x = seekRect.width();
}
MotionEvent me = MotionEvent.obtain(event.getDownTime(), event.getEventTime(),
event.getAction(), x, y, event.getMetaState());
return mSeekBar.onTouchEvent(me);
}
return false;
}
});
网友评论