我正在使用android seekBar
作为相机缩放 Controller 。
拖动时,搜索栏的工作原理像一个 super 按钮,但我想添加一个zoomIn和zoomOut按钮,以增加进度。问题是两方面的。
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;
}
}
我将其添加到我的 Activity 中,如下所示:
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);
最佳答案
通过重写VerticalSeekbar类中的setProgress解决了该问题。@Override public synchronized void setProgress(int progress) { super.setProgress(progress); onSizeChanged(getWidth(), getHeight(), 0, 0); }
关于android - 我可以使用setProgress以编程方式更改搜索栏吗,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/13764411/