Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make a linearLayout partially transparent in android?

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.

like image 805
user2137817 Avatar asked Oct 23 '13 12:10

user2137817


People also ask

How do I make my background transparent on Android?

getBackground(). setAlpha(51); Here you can set the opacity between 0 (fully transparent) to 255 (completely opaque). The 51 is exactly the 20% you want.


2 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); 
like image 64
arshu Avatar answered Oct 09 '22 07:10

arshu


Use this in your Layout

android:alpha="0.5" 

0.0 is totally transparent, 1.0 is fully opaque.

like image 22
Gajendra Rawat Avatar answered Oct 09 '22 06:10

Gajendra Rawat