seekbar thumb center not at the start point

纵然是瞬间 提交于 2019-12-05 09:31:58
Muhammed Refaat

finally found the answer, the case here is that android:thumbOffset is NOT a setter for the thumb place along with the progress bar, but, it's the thumb length from it's beginning to it's center point so that the seekbar can adjust the thumb's center point at it's beginning point. So, if we have a thumb image with a width of 50, the thumbOffset has to be 25 (50/2), so that the seekbar will adjust the zero value at the pixel 25 of the thumb which will make the thumb appears to be exactly at the middle. thanks for that man who redirect me to know that.

Your thumb image needs to have it's yellow dot at the center (horizontally); add transparent pixels left or right to make it so. Then, change android:thumbOffset to be exactly half your thumb image size. For example, if your image is 10dp in width, set android:thumbOffset to 5dp.

For me solution is to add android:thumbOffset value as suitable for your layout rather than setting it as half of your thumb icon width. If you set android:thumbOffset as +ve value (e.g 10dp) your thumb moves towards left side and this value is -ve (e.g -10dp) than your thumb moves towards right side.

try giving the thumbOffset in the seekbar a negative value (like -3px).

Add:

android:progress="0"

for seekbar in xml file.

OR

in Java activity file:

SeekBar sb = (SeekBar) v.findViewById(R.id.bright_seekbar);
sb.setMax(100);
sb.setProgress(0); // Set it to zero so it will start at the left-most edge

This should solve your problem.

Set thumbOffset of your seekbar equal to double of thumb width. If width of your thumb is 8dp, then set android:thumbOffset equal to 16dp. It worked in my case.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!