目前有些懒人总是抄别人的代码,抄会了Seekbar但是又不想修改成ProgressBar,另外Progressbar不能像SeekBar那样方便的setProgress.
居于此,搜集了网上http://www.eoeandroid.com/thread-162111-1-1.html参考了下,觉得有道理。自己写了如下心得顺便完善下,懒人们,抄吧!
1.定义一个类,这个我是照搬上面网址的,也可参照java
2.定义seekbar控件,参照xml
3.还有吗?没有了,over了,已经拖不动了。懒吧!?
====================.java===============================
public class MySeekBar extends SeekBar {
public MySeekBar(Context context) {
super(context);
// TODO Auto-generated constructor stub
}
public MySeekBar(Context context, AttributeSet attrs) {
this(context, attrs, android.R.attr.seekBarStyle);
}
public MySeekBar(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
/**
* onTouchEvent 是在 SeekBar 继承的抽象类 AbsSeekBar 里 你可以看下他们的继承关系
*/
@Override
public boolean onTouchEvent(MotionEvent event) {
// TODO Auto-generated method stub
// 原来是要将TouchEvent传递下去的,我们不让它传递下去就行了
// return super.onTouchEvent(event);
return false;
}
}
=====================.xml=================================
<LinearLayout
android:layout_gravity="center_vertical"
android:gravity="center_vertical"
android:layout_width="wrap_content"
android:layout_height="18dp"
android:orientation="vertical" >
<com.ls.onlineeye.util.MySeekBar
android:id="@+id/time_contorl_seekbar"
style="@style/progressBarStyleFloateView"
android:thumb="@drawable/red_thumb"
android:progressDrawable="@drawable/red_seek"
android:layout_width="100dp"
android:layout_height="5dp"
android:layout_gravity="center_vertical"
android:layout_marginLeft="1dp"
android:layout_marginTop="1dp"
android:background="@drawable/seek_bg"
android:paddingLeft="0dip"
android:paddingRight="0dip" />
</LinearLayout>