使用 SeekBars 的 RGB 比例不完整

RGB scale isn't complete using SeekBars

我创建了一个简单的项目,它使用 SeekBars 连接到声音并连接到按钮的颜色。

我对声音没有问题,但对 RGB 色阶有问题。我写了代码,但是当我在 phone 上安装 apk 时,我发现了一个错误。当我将光标移动到最后时,色阶不完整,像这样:

如果您看到了,则表示比例尺并未处于其颜色范围的末端。其他两个 RGB SeekBars 也存在此问题。

有代码,我做错了什么?

    final SeekBar r=(SeekBar)findViewById(R.id.seekBar3);
    final SeekBar g=(SeekBar)findViewById(R.id.seekBar4);
    final SeekBar b=(SeekBar)findViewById(R.id.seekBar5);
    r.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
        @Override
        public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
            seekr = r.getProgress();
            seekg = g.getProgress();
            seekb = b.getProgress();

            button1.setBackgroundColor(
                    0xff000000
                            + seekr * 0x10000
                            + seekg * 0x100
                            + seekb
            );

            button2.setBackgroundColor(
                    0xff000000
                            + seekr * 0x10000
                            + seekg * 0x100
                            + seekb
            );


        }

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {

            //mplayer.start();
        }

        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {
            //mplayer.stop();

        }
    });

    g.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
        @Override
        public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
            seekr = r.getProgress();
            seekg = g.getProgress();
            seekb = b.getProgress();
            button1.setBackgroundColor(
                    0xff000000
                            + seekr * 0x10000
                            + seekg * 0x100
                            + seekb
            );
            button2.setBackgroundColor(
                    0xff000000
                            + seekr * 0x10000
                            + seekg * 0x100
                            + seekb
            );


        }

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {

            //mplayer.start();
        }

        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {
            //mplayer.stop();

        }
    });
    b.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
        @Override
        public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
            seekr = r.getProgress();
            seekg = g.getProgress();
            seekb = b.getProgress();
            button1.setBackgroundColor(
                    0xff000000
                            + seekr * 0x10000
                            + seekg * 0x100
                            + seekb
            );
            button2.setBackgroundColor(
                    0xff000000
                            + seekr * 0x10000
                            + seekg * 0x100
                            + seekb
            );


        }

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {

            //mplayer.start();
        }

        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {
            //mplayer.stop();

        }
    });

}

XML:

   <SeekBar
       android:id="@+id/seekBar3"
       android:layout_width="305dp"
       android:layout_height="31dp"
       tools:layout_editor_absoluteX="59dp"
       tools:layout_editor_absoluteY="365dp"
       android:layout_marginTop="25dp"
       android:layout_below="@+id/button2"
       android:layout_alignStart="@+id/button" />

   <SeekBar
       android:id="@+id/seekBar4"
       android:layout_width="309dp"
       android:layout_height="27dp"
       tools:layout_editor_absoluteX="59dp"
       tools:layout_editor_absoluteY="459dp"
       android:layout_marginTop="30dp"
       android:layout_below="@+id/seekBar3"
       android:layout_alignStart="@+id/button" />

   <SeekBar
       android:id="@+id/seekBar5"
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"
       android:layout_alignStart="@+id/seekBar4"
       android:layout_below="@+id/seekBar4"
       android:layout_marginTop="19dp"
       android:layout_alignEnd="@+id/seekBar4" />

您应该在 xml 文件中使用 android:max="255" 将搜索栏的最大值定义为 255。

正如 android 文档中所写:

By default, the progress bar is full when it reaches 100. If necessary, you can adjust the maximum value (the value for a full bar) using the android:max attribute.