【问题标题】:Setting alpha of background of layout using setAlpha doesn't work使用 setAlpha 设置布局背景的 alpha 不起作用
【发布时间】:2018-07-19 13:42:14
【问题描述】:

我有点困惑。 我有这个:

this.opacitySeekbar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
        @Override
        public void onProgressChanged(SeekBar seekBar, int i, boolean b) {
            // updating opacity of layout
            RelativeLayout ledColor;
            for(int index = 0; index < selectedLedsIndices.size(); index++) {
                ledColor = (RelativeLayout)ledsLayout.getChildAt(index).findViewById(R.id.led_color);
                ledColor.setAlpha(((float)i) / 255); 
            }

        }

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {

        }

        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {

        }
    });

我正在尝试使用搜索栏的进度值更改布局的不透明度。 seekbar 的值从 à 变为 255。但是在运行时,布局的不透明度不会改变。我没有得到任何错误跟踪。它只是不想改变。怎么样?

我在 api 24 上运行应用程序(我的应用程序应该以 19 到 27 的 api 为目标)。

【问题讨论】:

  • 什么是ledsLayout,什么是ledColor?发布您的 xml 并明确您想要更改其 alpha 的布局以及您如何访问它。

标签: android android-layout alpha android-seekbar


【解决方案1】:

使用ledColor.getBackground().setAlpha(...)

【讨论】:

  • 它仍然不起作用............我在一个片段中工作,但它不应该是一个问题......我真的不知道在哪里是问题所在。
猜你喜欢
  • 2020-12-08
  • 2017-04-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-02-14
  • 2020-01-22
相关资源
最近更新 更多