Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I make an image transparent on Android?

I am using a linear layout and frame layout. In the linear layout I keep an image as background and in the frame layout I keep an imageView. In that imageView I give an image.

Now I want to make the second image (that is in the imageView) transparent. How can I do this?

like image 421
khan Avatar asked Feb 22 '11 12:02

khan


People also ask

How can I make an image transparent?

Double-click the picture, and when Picture Tools appears, click Picture Tools Format > Color. Click Set Transparent Color, and when the pointer changes, click the color you want to make transparent.

How do I make a picture transparent in gallery?

You can create a transparent area in most pictures. Select the picture that you want to create transparent areas in. Click Picture Tools > Recolor > Set Transparent Color. In the picture, click the color you want to make transparent.

How do I change transparency on Android?

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


1 Answers

Try this:

ImageView myImage = (ImageView) findViewById(R.id.myImage); myImage.setAlpha(127); //value: [0-255]. Where 0 is fully transparent and 255 is fully opaque. 

Note: setAlpha(int) is deprecated in favor of setAlpha(float) where 0 is fully transparent and 1 is fully opaque. Use it like: myImage.setAlpha(0.5f)

like image 53
Rubycon Avatar answered Oct 02 '22 06:10

Rubycon