android - 默认 Seekbar 缩略图被截断

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

我试着像其他人建议的那样将左右填充设置为拇指宽度的一半,但它看起来仍然像上图,我真的不知道还能做什么,任何帮助将不胜感激。谢谢!

最佳答案

您需要设置 minHeightma​​xHeight 属性或您的 Seekbar,因为 Android 在放置拇指时会将它们考虑在内。

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

关于android - 默认 Seekbar 缩略图被截断,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25694648/

相关文章:

android - Admob child 定向设置

Android Studio - 应用程序文件夹在哪里?

android - 反转 SeekBar 值并使用对数/指数刻度

android - 如何取消线程

android - SeekBar Thumb 位置问题

java - Libgdx 近战攻击碰撞检测

android - 当我搜索城市(或任何非国家/地区名称)时,Android 中的地理位置抛出异常与国家/地区名称配合良好

Android:如何为 TextView 和 Layout 关闭抗锯齿

android - 停用滑动 SeekBar(或用拇指创建进度条...)

Android Seekbar 通过用户输入设置进度