Why is the text moving in SeekBar?
-
I redesigned SeekBar because over the thumb crawl, the text changes its position with the podium, but it also changes its position vis-à-vis the shelf. How do you fix that I missed?
@SuppressLint("AppCompatCustomView") public class SuperSeekBar extends SeekBar { Paint p; Rect rect;
public SuperSeekBar(Context context) { super(context); p = new Paint(); } public SuperSeekBar(Context context, AttributeSet attrs) { super(context, attrs); p = new Paint(); setOnSeekBarChangeListener(this); } public SuperSeekBar(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); p = new Paint(); } public SuperSeekBar(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { super(context, attrs, defStyleAttr, defStyleRes); p = new Paint(); } @Override protected void onSizeChanged(int w, int h, int oldw, int oldh) { super.onSizeChanged(w, h, oldw, oldh); Log.i("tag",""); } @Override protected void onDraw(Canvas c) { super.onDraw(c); float thumb_x = ((float)this.getProgress()/(float)this.getMax() ) *(float)this.getWidth(); float middle = (float)this.getHeight()/2.0f; p.setColor(Color.BLUE); c.drawText("TEXT", thumb_x, middle, p ); }
}
-
On another point on Stackowerflow found the answer: https://stackoverflow.com/questions/20493577/android-seekbar-thumb-position-in-pixel
float middle = (float)this.getHeight()/2.0f;
float thumbPos = (float)getPaddingLeft() + width * (float) getProgress() / (float) getMax(); p.setColor(Color.BLUE); c.drawText("TEXT", thumbPos, middle, p );