我正在使用android seekBar
作为相机变焦控制器。
搜索栏在拖动时就像魅力一样,但我想添加一个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){ }
}
});
有人可以帮忙吗?
此外:
这是我使用的verticalSeekBar类而不是seekBar:
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);
答案 0 :(得分:8)
通过覆盖VerticalSeekbar类中的setProgress解决了这个问题。
@Override
public synchronized void setProgress(int progress) {
super.setProgress(progress);
onSizeChanged(getWidth(), getHeight(), 0, 0);
}
答案 1 :(得分:3)
创建updateThumb(); VerticalSeekbar中的方法
public void updateThumb(){
onSizeChanged(getWidth(), getHeight(), 0, 0);
}
然后在设置进度后调用update thumb方法。
seekBar.setProgress(100 - (int) progress);
seekBar.updateThumb();