我的父布局中有一个子布局。如果我为父级设置任何背景颜色,它也会为其子级设置相同的颜色。但我不想为孩子设置相同的颜色。 (我希望默认的android黑色作为孩子的背景)。请帮我。 编辑: 我需要捕获子布局并稍后创建一个位图,所以我不应该为子设置任何背景颜色(但它的父颜色应该有一些颜色)。它应该设置为默认的android黑色。
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#FFA500" >
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center"
android:layout_margin="15dp"
android:layout_weight="1"
android:gravity="center" >
</RelativeLayout>
</LinearLayout>
父线性布局具有一些BG颜色。我没有为儿童相对布局设置任何BG颜色,但它采用父母的BG颜色。所以现在,我怎样才能为孩子设置android默认的BG颜色?
如果我为父级设置任何背景颜色,它也会为其子级设置相同的颜色
不,不。您的孩子默认情况下只有透明背景,所以它看起来像是从父母那里继承颜色。只需将其设置为透明以外的其他内容即可。
编辑:
对不起,请阅读您的修改。
如果您想稍后将图像添加到子视图中,请使用setBackgroundDrawable
,而不是设置setImageBitmap
或其他内容。它将保留子视图的透明色,同时显示您指定的图像。
您可以将子布局的背景颜色设置为透明。
组:
android:background="00000000";
前2个十六进制数字是背景的alpha分量。