I have a RelativeLayout
containing 2 LinearLayouts
one of them is partially covering the other. I want to make the part of the LinearLayout
on top transparent so I can also see the 2nd LinearLayout
knowing that i have 2 images as background for the 2 LinearLayouts
.

- 1,825
- 5
- 28
- 45
-
so you want the covered part of layout 1 which is partially covering layout 2, transparent? – johntheripp3r Oct 23 '13 at 12:58
-
@user2137817 can u post ur layout code? I am in need of the same thing what u posted – ydnas Feb 20 '14 at 14:17
7 Answers
When we set the color it is like ARGB(Alpha Red Green Blue). You need to change the alpha in the color code to increase or decrease the amount of Transparency :
You can range it from 00 to FF (Hexa Decimal)
For maximum transparency => #00555555 (Here 00 stands for the alpha)
For minimum or no transparency => #FF555555 (Here FF stands for the alpha)
So, for setting the transparency of an ImageView you can code like this:
ImageView image = (ImageView) findViewById(R.id.myImage);
image.setAlpha(0.3);
Also, you can set the alpha for your LinearLayout like this :
LinearLayout ll = (LinearLayout) findViewById(R.id.linearlayout);
ll.setAlpha(0.4);

- 11,805
- 3
- 23
- 21
-
2the problem is, if i change the alpha for a linealayout, the children will be transparent as well and i don't want that – user2137817 Oct 23 '13 at 12:53
-
Then make your LinearLayout transparent. Then add a ImageView and control the transparency of that ImageView. – arshu Oct 23 '13 at 12:55
-
my problem is the children, i have text views inside the linealayout and if i modify the alpha value, the textviews become transparent aswell – user2137817 Oct 23 '13 at 13:19
-
Read my previous comment properly. You need to add an ImageView to take for containing the image and above it place the TextViews. – arshu Oct 23 '13 at 13:22
-
-
However this causes a crash on Api 6 and Api 4.4 have you faced this crash ? – Samir Jun 26 '19 at 08:57
Use this in your Layout
android:alpha="0.5"
0.0 is totally transparent, 1.0 is fully opaque.

- 2,735
- 1
- 29
- 36

- 3,673
- 2
- 19
- 36
-
Why did i have to look for an answer like this for half an hour..? So goddamn simple yet affective, nice! – Sindri Þór Sep 19 '15 at 22:41
-
Well that didn´t last long.. it failed on build-time with: "String types not allowed (at 'alpha' with value '0.5f')." – Sindri Þór Sep 19 '15 at 22:43
-
1
Make your LinearLayout
Background Transparent :
android:background="@android:color/transparent"
and for making your Layout Partially Transparent maybe this Link Helps you : How to create View partially invisible
Edit: if you have an Image as Background of your layout so i think you can set alpha for your LinearLayout and control it from code without changing your background, to Transparent your Layout with Background Image :
android:alpha=""
alpha property of the view, as a value between 0 (completely
transparent) and 1 (completely opaque)
set Top Linear Layout's background as
background="#CCFFFFFF" in your layout.xml file
change alpha mode for more transparency here "CC".
("00" as full transparent)

- 1
- 1

- 3,151
- 4
- 32
- 50
It is so late but it will be helpful for others....
create xml file like this...
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
>
<LinearLayout
android:id="@+id/l1"
android:layout_width="190dp"
android:layout_height="match_parent"
android:background="#234234"
android:orientation="vertical" >
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="onClickNext"
android:text="Next >" />
</LinearLayout>
<LinearLayout
android:id="@+id/l2"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1"
android:alpha=".05"
android:orientation="vertical" >
</LinearLayout>
</LinearLayout>
now go to your manifest... and add this line...
<activity android:name=".Activity"
android:theme="@android:style/Theme.Translucent">
enjoyyyy...

- 1,479
- 1
- 22
- 42
set the background color like this:
android:background="#00ffffff"

- 74,896
- 15
- 165
- 198

- 161
- 1
- 4
Add the theme to the activity which needs to be transparent in your Manifest file.
<activity android:name=".YourActivity"
android:theme="@android:style/Theme.Translucent">
</activity>

- 2,096
- 5
- 23
- 40