Search code examples
androidlayouttransparentalpha

how i i can transparent background on android studio?


i want to design a layout exactly like image below.

when i put my linear layout alpha as transparent , all icons inside it also become transparent and its completely normal. but i want a way to just have transparent background not all items !

i want a transparent layout like this:

enter image description here

but my layout shows like this :

enter image description here

here is my code :

    <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>

Solution

  • You can try like this if you want to adjust the transparent change the alpha in color I gave as #55000000 you can change the alpha value(55) whatever you want. if you wish black transparency you can use #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>