android - 使用 setAlpha 设置布局背景的 alpha 不起作用
问题描述
我有点困惑。我有这个 :
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 上运行应用程序(我的应用程序应该针对 api 从 19 到 27)。
解决方案
利用ledColor.getBackground().setAlpha(...)
推荐阅读
- solr - 如何从 Solr 中提取 BM25 分数
- java - 如何显示图像 30 秒,然后在 30 秒后显示另一张图像以显示多张图像?
- node.js - 如何在nodejs服务器代码中使用Mailgun以html形式将文件发送到邮件?
- react-native - 如何在本机反应中更改活动页脚选项卡颜色?
- reactjs - React - 单元测试 HOC 的包装组件 - 测试状态
- python - 如何遍历 JSON 数组并获取本身是 JSON 对象的键的值
- python - 未解决的导入'pubsub'
- scala - 使用 <:< 的 Nothing 的隐式解析失败
- python - 用 Sympy 求解线性方程组
- r - 如何从 R 中的字符串中提取文本的特定部分?