How to make a linearLayout partially transparent in android?

user2137817 picture user2137817 · Oct 23, 2013 · Viewed 91.4k times · Source

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.

Answer

arshu picture arshu · Oct 23, 2013

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