如何让seekbar thumb不超过progress margin?

问题描述 投票:0回答:0

创建我的自定义 seekBar 时遇到问题,因为拇指超出了 seekBar 的进度条,我希望拇指到达 seekbar 边距的末端而不超过它,问题:

enter image description here

我希望拇指不要超出搜索栏的进度条,只是触及它的边距。例如:

enter image description here

enter image description here .

seekbar的线性代码:

LinearLayout linearLayout = new LinearLayout(this);
LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(-1, dp(30));
linearLayout.setPadding(5, 5, 0, 5);       
layoutParams.setMargins(dp(3), dp(1), dp(2), dp(4));       
linearLayout.setOrientation(LinearLayout.VERTICAL);
linearLayout.setGravity(Gravity.CENTER);       linearLayout.setBackgroundColor(Color.parseColor("#000000"));
linearLayout.getBackground().setAlpha(1);
linearLayout.setLayoutParams(layoutParams);

代码搜索栏:

        seekBar.setProgressDrawable(seekbarProgressOff);
        seekBar.setPadding(25, 10, 35, 10);
        seekBar.setSplitTrack(false);
        seekBar.setLayoutParams(new LinearLayout.LayoutParams(-1, dp(18)));
        seekBar.setMax(max);
        seekBar.setProgress(prog);
        seekBar.setElevation(0);
        seekBar.setProgressDrawable(seekbarProgressOff);
        seekBar.setPadding(25, 10, 35, 10);
        seekBar.setSplitTrack(false);
        seekBar.setLayoutParams(new LinearLayout.LayoutParams(-1, dp(18)));
        seekBar.setMax(max);
        seekBar.setProgress(prog);
        seekBar.setElevation(0);

谁能帮帮我谢谢。

java android seekbar
© www.soinside.com 2019 - 2024. All rights reserved.