Java android-透明的RelativeLayout
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18460321/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
android- transparent RelativeLayout
提问by Soheil
I want to make an activity which has a gradient drawable as background and is going to show 4 panels (RelativeLayout) on top of it's background. now I want to make the 4 panels transparent(e.g. 50%) so that the gradient background could be seen, too. I searched google, but I found only ways to do this with activities not layouts. how to do what I want?
我想制作一个具有可绘制渐变背景的活动,并将在其背景上显示 4 个面板(RelativeLayout)。现在我想让 4 个面板透明(例如 50%),以便也可以看到渐变背景。我搜索了谷歌,但我发现只有通过活动而不是布局来做到这一点的方法。如何做我想做的事?
采纳答案by Saeed
You can create a drawable
with shape
content. And put your styles in it.
您可以创建一个drawable
与shape
内容。并把你的风格放进去。
Sample:
样本:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<solid android:color="#77ffffff"/>
</shape>
Create a file with a name such as sampleBackground.xml
in the drawable folder in the res path. And set the
background attribute of your panels to it:
sampleBackground.xml
在 res 路径中的 drawable 文件夹中创建一个具有名称的文件。并将面板的背景属性设置为:
android:background="@drawable/sampleBackground"
回答by DroidDev
You can use alpha attribute for your layout if you want to make it transparent. It can be used in following way:-
如果要使其透明,可以为布局使用 alpha 属性。它可以通过以下方式使用:-
<RelativeLayout
android:id="@+id/yourRelativeLayoutID"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:alpha="0.7"
android:gravity="bottom">
</RelativeLayout>
set the value of alpha between 0.1 to 1.0. It depends on level of transparency you want.
将 alpha 值设置在 0.1 到 1.0 之间。这取决于您想要的透明度级别。
Hope this helps. :)
希望这可以帮助。:)
回答by invisbo
You can use this:
你可以使用这个:
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:color/transparent" >
</RelativeLayout>
回答by L0j1k
I was able to get a transparent background on RelativeLayout elements by specifying a background color:
通过指定背景颜色,我能够在 RelativeLayout 元素上获得透明背景:
<RelativeLayout
android:layout_height="match_parent"
android:layout_width="wrap_content"
android:background="@color/modal_background" >
</RelativeLayout>
And in my colors.xml
I created a color called modal_background
with an alpha value. This particular example is black (#000000
) with an alpha value of CC
:
在我的中,colors.xml
我创建了一个modal_background
带有 alpha 值的颜色。此特定示例是黑色 ( #000000
),其 alpha 值为CC
:
<resources>
<item name="modal_background" type="color">#CC000000</item>
</resources>