使用SeekBars时,RGB刻度不完整

时间:2017-05-13 06:54:38

标签: android rgb seekbar

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

我没有声音问题,但使用RGB色标。我写了代码但是当我在手机上安装apk时,我发现了一个错误。当我将光标移动到最后时,色标不完整,如下所示:

enter image description here

如果您看到,比例不在其颜色范围的末尾。其他两个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" />

1 个答案:

答案 0 :(得分:0)

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

正如在android文档中所写:

  

默认情况下,进度条在达到100时已满。如有必要,您可以使用android:max属性调整最大值(完整条的值)。