我怎么能在Android工作室透明背景?

时间:2017-07-07 08:14:26

标签: android layout transparent alpha

我想设计一个与下图完全相同的布局。

当我将线性布局alpha设置为透明时,其中的所有图标也变得透明且完全正常。但我想要一种透明背景而不是所有物品的方法!

我想要一个像这样的透明布局:

enter image description here

但我的布局显示如下:

enter image description here

这是我的代码:

    <LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="100dp"
    android:background="@color/colorPrimary"
    android:orientation="vertical"
    android:alpha="0.5"
    >



    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:alpha="1"
        >

        <RelativeLayout
            android:layout_width="1dip"
            android:layout_height="fill_parent"
            android:layout_weight="0.333"
            android:padding="10dp"
            >

            <ImageView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="@mipmap/consert"
                android:layout_gravity="center_horizontal"
                />

        </RelativeLayout>
        <RelativeLayout
            android:layout_width="1dip"
            android:layout_height="fill_parent"
            android:layout_weight="0.333"
            android:padding="10dp">

            <ImageView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="@mipmap/consert"
                android:layout_gravity="center_horizontal"
                />

        </RelativeLayout>
        <RelativeLayout
            android:layout_width="1dip"
            android:layout_height="fill_parent"
            android:layout_weight="0.333"
            android:padding="10dp">

            <ImageView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="@mipmap/consert"
                android:layout_gravity="center_horizontal"
                />

        </RelativeLayout>
    </LinearLayout>



    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        >

        <RelativeLayout
            android:layout_width="1dip"
            android:layout_height="fill_parent"
            android:layout_weight="0.333">

            <ImageView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="@mipmap/consert"
                android:layout_gravity="center_horizontal"
                />

        </RelativeLayout>
        <RelativeLayout
            android:layout_width="1dip"
            android:layout_height="fill_parent"
            android:layout_weight="0.333">

            <ImageView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="@mipmap/consert"
                android:layout_gravity="center_horizontal"
                />

        </RelativeLayout>
        <RelativeLayout
            android:layout_width="1dip"
            android:layout_height="fill_parent"
            android:layout_weight="0.333">

            <ImageView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="@mipmap/consert"
                android:layout_gravity="center_horizontal"
                />

        </RelativeLayout>
    </LinearLayout>

</LinearLayout>

3 个答案:

答案 0 :(得分:2)

如果您想调整透明变化,我可以尝试这样做我给出的颜色为#55000000你可以随意更改alpha值(55)。如果您希望黑色透明度,您可以使用#55FFFFFF

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:layout_width="match_parent"
              android:layout_height="match_parent"
              android:background="@color/colorPrimary"
              android:orientation="vertical"
    >


    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="100dp"
        android:background="#55000000"
        android:orientation="vertical">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="horizontal"
            android:weightSum="3"
            >

            <RelativeLayout
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:padding="10dp"
                >

                <ImageView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_centerInParent="true"
                    android:background="@mipmap/ic_launcher"
                    />

            </RelativeLayout>

            <RelativeLayout
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:padding="10dp"
                >

                <ImageView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_centerInParent="true"
                    android:background="@mipmap/ic_launcher"
                    />

            </RelativeLayout>

            <RelativeLayout
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:padding="10dp"
                >

                <ImageView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_centerInParent="true"
                    android:background="@mipmap/ic_launcher"
                    />

            </RelativeLayout>
        </LinearLayout>


        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="horizontal"
            android:weightSum="3"
            >

            <RelativeLayout
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:padding="10dp"
                >

                <ImageView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_centerInParent="true"
                    android:background="@mipmap/ic_launcher"
                    />

            </RelativeLayout>

            <RelativeLayout
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:padding="10dp"
                >

                <ImageView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_centerInParent="true"
                    android:background="@mipmap/ic_launcher"
                    />

            </RelativeLayout>

            <RelativeLayout
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:padding="10dp"
                >

                <ImageView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_centerInParent="true"
                    android:background="@mipmap/ic_launcher"
                    />

            </RelativeLayout>
        </LinearLayout>
    </LinearLayout>

</LinearLayout>

答案 1 :(得分:0)

对于透明

android:background="00000000";

黑色透明(根据您的情况)

android:background="55000000";

答案 2 :(得分:0)

这段透明代码也对我有用:

android:background="@null"

另一方面,对于黑色透明度(正如其他人之前回答的那样)

android:background="55000000"
相关问题