简体   繁体   中英

Default Seekbar Thumb Cut off

I looked at other links and tried what they said and nothing seemed to work, but when I add a seekbar the thumb ends up getting cut off like this:

在此处输入图片说明

This is what I have:

public void addSeekBar(int topMargin, int leftMargin, int width, int height, final int myWidth) {
    View st = new SeekBar(getBaseContext());
    SeekBar slider = new SeekBar(st.getContext());

    slider.setMax(9);
    slider.setProgress(5);

    slider.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {

        public void onStopTrackingTouch(SeekBar seekBar) {

        }

        public void onStartTrackingTouch(SeekBar seekBar) {

        }

        @Override
        public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {

            drawStars((float) ((progress + 1) / 2.0), myWidth);

        }
    });
    LayoutParams paramsText = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
    paramsText.leftMargin = leftMargin;
    paramsText.topMargin = topMargin;
    paramsText.width = width;
    paramsText.height = height;

    //Other threads said to set the left and right margin to half the width
    //of the thumb and set the thumb offset to 8, I did this here but it didn't
    //seem to work
    slider.setPadding(16, 0, 16, 0);
    slider.setThumbOffset(8);

    container.addView(slider, paramsText);
}

I tried to set the right and left padding to half the width of the thumb like other people suggested and it still looked like the above picture, I'm really not sure what else to do, any help would be greatly appreciated. Thanks!

You need to set the minHeight and maxHeight attributes or your Seekbar because Android takes them into account when placing the thumb.

Here is more info around that issue: http://qtcstation.com/2011/05/android-how-to-fix-seekbar-bar-thumb-centering-issues/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM