2

In my app I want to change the ImageView like the following. I want only to change the image on the body.

enter image description here

I have followed the following link to change the alpha values by using the code like that

imageView.setAlpha(255);

But it is not working.

How to Set Opacity (Alpha) for View in Android. Please anybody suggest me how to do that.

Community
  • 1
  • 1
rams
  • 1,558
  • 7
  • 25
  • 48

3 Answers3

4

Or, without using animation you can just use setAlpha(float alpha) on your ImageView.

Ovidiu Latcu
  • 71,607
  • 15
  • 76
  • 84
  • setalpha is available for api 11+! – Arash Jan 29 '14 at 16:29
  • whenever I try to put alpha by this method I cant see any changes! iv.setAlpha(50f) or iv.setImageAlpha(50) nothing happens ? WHY – Cyph3rCod3r Mar 28 '14 at 05:25
  • As written in android developer doc : . This is a value from 0 to 1, where 0 means the view is completely transparent and 1 means the view is completely opaque. You should try with setAlpha(0.2f) – phyzalis Apr 04 '14 at 10:45
4

It might be because setAlpha(float Alpha) has been deprecated as of API level 16 by setImageAlpha(float Alpha)

7heViking
  • 7,137
  • 11
  • 50
  • 94
1

Opacity ranges between 0 to 1, and you have given the value as 255,
imageView.setAlpha(255).

So give the value between 0 to 1, such as when

you want the opacity of 50%, give 0.5. imageView.setAlpha(0.5f)

Also you can do it in XML file as follows:

android:layout_width="100dip"
android:layout_height="100dip"
android:id="@+id/imageViewIcon"
android:src="@drawable/icon"
android:alpha=".5"

Amit Anand
  • 11
  • 2