默认Seekbar Thumb截止

时间:2014-09-05 22:07:23

标签: android seekbar

我查看了其他链接并尝试了他们所说的内容,似乎没有任何效果,但是当我添加一个搜索栏时,拇指最终会被切断:

enter image description here

这就是我所拥有的:

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

我尝试将右边和左边的边距设置为拇指的宽度的一半,就像其他人建议的那样,它仍然看起来像上面的图片,我真的不知道还能做什么,任何帮助都会很大赞赏。谢谢!

1 个答案:

答案 0 :(得分:1)

您需要设置 minHeight maxHeight 属性或您的Seekbar,因为Android在放置拇指时会考虑它们。

以下是有关该问题的更多信息:http://qtcstation.com/2011/05/android-how-to-fix-seekbar-bar-thumb-centering-issues/