我从here获得了以下代码,它绘制了一个垂直搜索栏:
import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.Canvas;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.widget.SeekBar;
public class VerticalSeekBar extends SeekBar {
private static final int ROTATION_ANGLE = -90;
private OnSeekBarChangeListener mOnSeekBarChangeListener;
public VerticalSeekBar(final Context context) {
super(context);
}
public VerticalSeekBar(final Context context, final AttributeSet attrs, final int defStyle) {
super(context, attrs, defStyle);
}
public VerticalSeekBar(final Context context, final AttributeSet attrs) {
super(context, attrs);
}
@Override
protected final void onSizeChanged(final int width, final int height, final int oldWidth, final int oldHeight) {
super.onSizeChanged(height, width, oldHeight, oldWidth);
}
@Override
protected final synchronized void onMeasure(final int widthMeasureSpec, final int heightMeasureSpec) {
super.onMeasure(heightMeasureSpec, widthMeasureSpec);
setMeasuredDimension(getMeasuredHeight(), getMeasuredWidth());
}
@Override
protected final void onDraw(final Canvas c) {
c.rotate(ROTATION_ANGLE);
c.translate(-getHeight(), 0);
super.onDraw(c);
}
@Override
public final void setOnSeekBarChangeListener(final OnSeekBarChangeListener l) {
mOnSeekBarChangeListener = l;
super.setOnSeekBarChangeListener(l);
}
@SuppressLint("ClickableViewAccessibility")
@Override
public final boolean onTouchEvent(final MotionEvent event) {
if (!isEnabled()) {
return false;
}
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
setProgress(getMax() - (int) (getMax() * event.getY() / getHeight()));
mOnSeekBarChangeListener.onStartTrackingTouch(this);
break;
case MotionEvent.ACTION_MOVE:
setProgress(getMax() - (int) (getMax() * event.getY() / getHeight()));
break;
case MotionEvent.ACTION_UP:
setProgress(getMax() - (int) (getMax() * event.getY() / getHeight()));
mOnSeekBarChangeListener.onStopTrackingTouch(this);
break;
case MotionEvent.ACTION_CANCEL:
mOnSeekBarChangeListener.onStopTrackingTouch(this);
break;
default:
break;
}
return true;
}
@Override
public final void setProgress(final int progress) {
super.setProgress(progress);
onSizeChanged(getWidth(), getHeight(), 0, 0);
}
}
此代码在Android 2.3上运行良好,但在Android 4.2.2中,拇指卡在滑块栏的底部:
答案 0 :(得分:0)
也许是因为
中的零onSizeChanged(getWidth(),getHeight(),0,0);
这是为数不多的东西之一,它们都是手工改变的。
此外,我注意到代码正在使用4.4.4和4.1.2。
/编辑/
这个包正在运行: http://560b.sakura.ne.jp/android/VerticalSlidebarExample.zip 感谢Andro Selva
答案 1 :(得分:0)
ipwcheat:sets(CustomInterface(round((show_circle,true)(y,574)(x,1651)(zoom,3.0)(btn_type,focus)(running,true))seekbar((vertical,false)(翻转,false)(y,1005)(x,635)(zoom,5.0)(running,true))))