ÉèΪÊ×Ò³ ¼ÓÈëÊÕ²Ø

TOP

AndroidʵÏÖ´¹Ö±Ð͵ÄSeekBar
2014-11-24 07:34:54 À´Ô´: ×÷Õß: ¡¾´ó ÖРС¡¿ ä¯ÀÀ:1´Î
Tags£ºAndroid ʵÏÖ ´¹Ö± SeekBar

°´ÒÔǰд×÷·½Ê½£¬Ê×ÏÈÉÏЧ¹ûͼ£º



¾ßÌåʵÏÖ·½Ê½ÊǼÌÐøSeekBar,ÖØÐ´onDraw·½·¨Ö»ÒªÐýת90¶È¾Í¿ÉÒÔʵÏÖ¡£


¸ø³öÒÔÉÏÁ½¸öÆäÖеÄÒ»¸ö´úÂ룺


package android.widget;

import android.content.Context;
import android.graphics.Canvas;
import android.util.AttributeSet;
import android.util.Log;
import android.view.MotionEvent;

public class VerticalSeekBar extendsSeekBar {

public VerticalSeekBar(Context context) {
super(context);
}

public VerticalSeekBar(Context context, AttributeSet attrs, intdefStyle) {
super(context, attrs, defStyle);
}

public VerticalSeekBar(Context context,AttributeSet attrs) {
super(context, attrs);
}

protected void onSizeChanged(int w, int h, int oldw, int oldh) {
super.onSizeChanged(h, w, oldh, oldw);
}

@Override
protected synchronized void onMeasure(int widthMeasureSpec, intheightMeasureSpec) {
super.onMeasure(heightMeasureSpec, widthMeasureSpec);
setMeasuredDimension(getMeasuredHeight(), getMeasuredWidth());
}

protected void onDraw(Canvas c) {
c.rotate(-90);
c.translate(-getHeight(),0);

super.onDraw(c);
}

@Override
public boolean onTouchEvent(MotionEvent event) {
if (!isEnabled()) {
return false;
}

switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
case MotionEvent.ACTION_MOVE:
case MotionEvent.ACTION_UP:
int i=0;
i=getMax() - (int)(getMax() * event.getY() / getHeight());
setProgress(i);
Log.i("Progress",getProgress()+"");
onSizeChanged(getWidth(),getHeight(), 0, 0);
break;

case MotionEvent.ACTION_CANCEL:
break;
}
return true;
}

}


¡¾´ó ÖРС¡¿¡¾´òÓ¡¡¿ ¡¾·±Ìå¡¿¡¾Í¶¸å¡¿¡¾Êղء¿ ¡¾ÍƼö¡¿¡¾¾Ù±¨¡¿¡¾ÆÀÂÛ¡¿ ¡¾¹Ø±Õ¡¿ ¡¾·µ»Ø¶¥²¿¡¿
·ÖÏíµ½: 
ÉÏһƪ£ºAndroid΢ÐÅSDK API µ÷ÓÃ½Ì³Ì ÏÂһƪ£ºAndroid¶¨ÖÆÊôÓÚÄã×Ô¼ºµÄµ¼º½À¸

ÆÀÂÛ

ÕÊ¡¡¡¡ºÅ: ÃÜÂë: (ÐÂÓû§×¢²á)
Ñé Ö¤ Âë:
±í¡¡¡¡Çé:
ÄÚ¡¡¡¡ÈÝ:

¡¤Linuxϵͳ¼ò½é (2025-12-25 21:55:25)
¡¤Linux°²×°MySQL¹ý³Ì (2025-12-25 21:55:22)
¡¤Linuxϵͳ°²×°½Ì³Ì£¨ (2025-12-25 21:55:20)
¡¤HTTP Åc HTTPS µÄ²î„ (2025-12-25 21:19:45)
¡¤ÍøÕ¾°²È«±ØÐ޿ΣºÍ¼ (2025-12-25 21:19:42)