Android and setting alpha for (image) view alpha

It's easier than the other response. There is an xml value alpha that takes double values.

android:alpha="0.0" thats invisible

android:alpha="0.5" see-through

android:alpha="1.0" full visible

That's how it works.


I am not sure about the XML but you can do it by code in the following way.

ImageView myImageView = new ImageView(this);
myImageView.setAlpha(xxx);

In pre-API 11:

  • range is from 0 to 255 (inclusive), 0 being transparent and 255 being opaque.

In API 11+:

  • range is from 0f to 1f (inclusive), 0f being transparent and 1f being opaque.

No, there is not, see how the "Related XML Attributes" section is missing in the ImageView.setAlpha(int) documentation. The alternative is to use View.setAlpha(float) whose XML counterpart is android:alpha. It takes a range of 0.0 to 1.0 instead of 0 to 255. Use it e.g. like

<ImageView android:alpha="0.4">

However, the latter in available only since API level 11.