2012-12-07 128 views
5

我正在使用android seekBar作爲相機變焦控制器。我可以使用setProgress以編程方式更改搜索欄:

拖動時,查找欄的作用就像一個魅力,但我想添加一個zoomIn和zoomOut按鈕來增加進度。問題是雙重的。

  1. 當我按一下按鈕我有進步其實之前增加

  2. 它沒有更新進度條

    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){ } 
        } 
    }); 
    

上拖動拇指點擊4次任何人都可以幫忙嗎?

此外:

這是我使用的,而不是搜索欄的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); 
+0

seekbar.setProgress(seekbar.getProgress()+ 5) 和seekbar.setOffsetThumb(INT偏移)或seekbar.setThumb(繪製) – Tobrun

+0

setThumb()?它已經設置.. setThumbOffset()?我如何確定偏移量int? – erik

+0

其實我不想重置偏移..多數民衆贊成不太好 – erik

回答

8

通過覆蓋s解決了這個問題VerticalSeekbar類中的etProgress。 @Override public synchronized void setProgress(int progress) { super.setProgress(progress); onSizeChanged(getWidth(), getHeight(), 0, 0); }

+0

解決我的問題:) –

+0

真的很棒的鏈接。 –

3

Create updateThumb();方法在VerticalSeekbar中

public void updateThumb(){ 
     onSizeChanged(getWidth(), getHeight(), 0, 0); 
    } 

然後在設置進度後調用更新縮略圖方法。

seekBar.setProgress(100 - (int) progress); 
seekBar.updateThumb(); 
相關問題