7

我想制作一个具有渐变可绘制背景的活动,并将在其背景上显示 4 个面板(RelativeLayout)。现在我想让 4 个面板透明(例如 50%),以便也可以看到渐变背景。我搜索了谷歌,但我发现只有用活动而不是布局来做到这一点。如何做我想做的事?

4

4 回答 4

13

您可以创建一个drawable内容shape。并把你的风格放进去。

样本:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >

    <solid android:color="#77ffffff"/>

</shape>

sampleBackground.xml在 res 路径中的 drawable 文件夹中创建一个名称如的文件。并将面板的背景属性设置为它:

android:background="@drawable/sampleBackground"
于 2013-08-27T08:25:15.047 回答
9

如果你想让它透明,你可以为你的布局使用 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>

将 alpha 的值设置在 0.1 到 1.0 之间。这取决于您想要的透明度级别。

于 2013-08-27T08:21:03.227 回答
5

你可以使用这个:

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@android:color/transparent" >
</RelativeLayout>
于 2013-08-27T08:46:28.633 回答
2

通过指定背景颜色,我能够在 RelativeLayout 元素上获得透明背景:

<RelativeLayout
    android:layout_height="match_parent"
    android:layout_width="wrap_content"
    android:background="@color/modal_background" >
</RelativeLayout>

在我的中,colors.xml我创建了一种名为modal_backgroundalpha 值的颜色。这个特殊的例子是黑色 ( #000000),alpha 值为CC

<resources>
    <item name="modal_background" type="color">#CC000000</item>
</resources>
于 2015-10-05T08:00:29.073 回答