我正在使用 androidseekBar
作为相机变焦控制器。
拖动时,搜索栏就像一个魅力,但我想添加一个可以增加进度的 zoomIn 和 zoomOut 按钮。问题是双重的。
当我单击按钮时,我必须在进度实际增加之前单击它 4 次
它没有更新进度条上的可拖动拇指
btn_zoomIn.setOnClickListener(new View.OnClickListener() { public void onClick(View view) { try { zoomCtrl.setProgress(zoomCtrl.getProgress()+1); onProgressChanged(zoomCtrl, zoomCtrl.getProgress(), true); } catch(Exception ex) { } } }); btn_zoomOut.setOnClickListener(new View.OnClickListener() { public void onClick(View view) { try { zoomCtrl.setProgress(zoomCtrl.getProgress()-1); } catch(Exception ex){ } } });
有人可以帮忙吗?
添加:
这是我使用而不是 seekBar 的 verticalSeekBar 类:
public class VerticalSeekBar extends SeekBar {
/**
* Instantiates a new vertical seek bar.
*
* @param context the context
*/
public VerticalSeekBar(Context context) {
super(context);
}
/**
* Instantiates a new vertical seek bar.
*
* @param context the context
* @param attrs the attrs
* @param defStyle the def style
*/
public VerticalSeekBar(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
/**
* Instantiates a new vertical seek bar.
*
* @param context the context
* @param attrs the attrs
*/
public VerticalSeekBar(Context context, AttributeSet attrs) {
super(context, attrs);
}
/* (non-Javadoc)
* @see android.widget.AbsSeekBar#onSizeChanged(int, int, int, int)
*/
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
super.onSizeChanged(h, w, oldh, oldw);
}
/* (non-Javadoc)
* @see android.widget.AbsSeekBar#onMeasure(int, int)
*/
@Override
protected synchronized void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(heightMeasureSpec, widthMeasureSpec);
setMeasuredDimension(getMeasuredHeight(), getMeasuredWidth());
}
/* (non-Javadoc)
* @see android.widget.AbsSeekBar#onDraw(android.graphics.Canvas)
*/
protected void onDraw(Canvas c) {
c.rotate(-90);
c.translate(-getHeight(), 0);
super.onDraw(c);
}
/* (non-Javadoc)
* @see android.widget.AbsSeekBar#onTouchEvent(android.view.MotionEvent)
*/
@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:
setProgress(getMax() - (int) (getMax() * event.getY() / getHeight()));
onSizeChanged(getWidth(), getHeight(), 0, 0);
break;
case MotionEvent.ACTION_CANCEL:
break;
}
return true;
}
}
我将它添加到我的活动中,如下所示:
zoomCtrl = new VerticalSeekBar(this);
zoomCtrl.setLayoutParams(zCtrl);
zoomCtrl.setProgressDrawable(getResources().getDrawable(R.drawable.zoombar_progress_bg));
zoomCtrl.setThumb(getResources().getDrawable(R.drawable.imagebtn_zoom_thumb));
zoomCtrl.setBackgroundDrawable(getResources().getDrawable(R.drawable.zoom_track));
zoomCtrl.setPadding(25, 0, 25, 0);
zoomCtrl.setOnSeekBarChangeListener(this);
rel.addView(zoomCtrl);