rams
rams

Reputation: 1580

how to change the alpha value of imageview

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.

Upvotes: 2

Views: 16505

Answers (3)

Amit Anand
Amit Anand

Reputation: 11

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"

Upvotes: 1

7heViking
7heViking

Reputation: 7577

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

Upvotes: 4

Ovidiu Latcu
Ovidiu Latcu

Reputation: 72311

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

Upvotes: 4

Related Questions