忽略父视图背景? [英] Ignore parent View background?

查看:71
本文介绍了忽略父视图背景?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在现实世界中,示例控制面板布局(如下)显示在其自己的FrameLayout(片段容器)中,并且(取决于应用程序是否在平板电脑上运行)显示在地图旁边,该地图的颜色由触发的颜色选择器设置通过颜色"按钮. (注意:地图和控制面板的背景不同.)

In the real world, the example control panel layout (below) appears within its own FrameLayout (Fragment container) and (depending on whether the app is running on a tablet) alongside a map, whose colours are set by a colorpicker fired by the 'colour' buttons. (NB: The map and the control panel have different backgrounds.)

从颜色选择器返回时,关联的贴图粒子和Button背景将使用新颜色进行更新.

On return from the colorpicker the associated map particle and the Button background are updated with the new color.

想法是(由用户观察)按钮的颜色与地图完全匹配.

The idea is that (as observed by the user) the colour of the button exactly matches the map.

当然不是! (除非所选择的颜色具有255-alpha).

And of course, it does not! (Unless the picked color has 255-alpha).

我知道这是预期的行为",但是有一个聪明的(或"hacky")技巧会消除父级背景(仅在Button子级之后),以便正确呈现子级背景色吗?

I know this is 'expected behaviour' but is there a clever (or 'hacky') trick that will obliterate the parent background (behind the Button child only) so that the child background color is correctly rendered?

控制面板布局和代码示例

Example Control Panel Layout and code

<LinearLayout android:id="@+id/settingsLL"
    android:orientation="vertical">
    <LinearLayout android:id="@+id/oneOfMany"
        android:orientation="horizontal">
        <TextView style="@style/wptedit_title" android:text="[some title]" />
        <Button style="@style/wptedit_color" android:id="@+id/colorBtn" />
    </LinearLayout>
</LinearLayout> 

// Control panel background
settingsLL.setBackgroundColor(0xFFD5FFDD);      
// Faint red tint gives desired map background not reflected by button
colorBtn.setBackgroundColor(0x04FF0000);        

推荐答案

一个更好的问题是:

如何将地图的Alpha-255背景颜色与其他任何颜色组合在一起以产生新的Alpha-255颜色,然后可以将其应用于控制面板按钮,以使控制面板按钮的外观不论控制面板背景如何,都与地图完全对应?

到目前为止,太好了! (请参阅android.support.v4.graphics.ColorUtils)

So far, so good! (See android.support.v4.graphics.ColorUtils)

colorBtn.setBackgroundColor(ColorUtils.compositeColors(pickedColor, mapBackgroundColor);

有关Doco的信息,请参见此处. 来源不在我的SDK中.我必须得到它

See here for the doco. The source wasn't in my SDK. I had to get it here.

这篇关于忽略父视图背景?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆