Android Seekbar thumb position in pixel
android, seekbar
Solution
I did this:
int width = seekBar.getWidth()
- seekBar.getPaddingLeft()
- seekBar.getPaddingRight();
int thumbPos = seekBar.getPaddingLeft()
+ width
* seekBar.getProgress()
/ seekBar.getMax();
Problem
How can I get current position of thumb in pixel for SeekBar? Currently I am trying to get the position on the bases of calculation. Screen width, Seek Bar width, current seek progress and all. But I am not able to get exact position out of it. Do any one have any idea? Coding for same is as below. I want to drow one component on top of SeekBar thumb. ``` translation = calculateTranslation(this.deviceScreenWidth, seekBarWidth, seekBar1T.getMax(), Integer.valueOf(ConstantData.seekbar_fifth.toString()), topComponentWidth, 0); if (currentapiVersion < android.os.Build.VERSION_CODES.HONEYCOMB){ TranslateAnimation anim = new TranslateAnimation(translation - 1, translation, 0, 0); anim.setFillAfter(true); anim.setDuration(0); edtTextRodUpDown.startAnimation(anim); }else{ edtTextRodUpDown.setTranslationX(translation); } ``` and calculate Translation like ``` private float calculateTranslation(int screenWidth, int seekBarWidth, int seekMaxProgress, int currentProgress, int componentWidth, int extraDifference){ double calculatedPosition = 0f; calculatedPosition = (double)((double)(seekBarWidth-((screenWidth-seekBarWidth))) / (double)seekMaxProgress) * (double)currentProgress; calculatedPosition = calculatedPosition - (double)(componentWidth/2); calculatedPosition = calculatedPosition + extraDifference; Double d = new Double(calculatedPosition); if(d < 0){ return 0.0f; }else if(d + componentWidth > screenWidth){ return screenWidth-componentWidth; }else{ return d.floatValue(); } } ```