Setting alpha representation at runtime is slow, how to speed it up?

I have two ImageViews that I hope imageViewA overlaps with imageViewB, and when the user selects the search drum, the alpha value of imageViewB will change accordingly (for example, it becomes translucent, and users can see part of the image ViewA).

He believes this is a simple coding task, however I found that the performance is very slow in my Galaxy S6.

I tried all setAlpha (int), setAlpha (float) and setImageAlpha (float) but did not get any hope. The most related question seems to be: Application UI operations (setting alpha, settings fields, etc.) Very slow at 4.4.4 compared to 4.0.3

However, this question is still open. Does anyone know how to speed it up?

---- Here are some updates ----

The minimal code is just simple, in the seekbar callback I did

imageViewB.setAlpha(selectedAlphaValue); 

VERY slow means that fps is less than 1 ~ 2. I hope I can get the alpha changed 10 times per second so that users feel comfortable. (By the way, I do not compare the delay of the given alpha function, because it is too slow, even my human eyes can notice that it changes only 1 ~ 2 times per second)

+1
performance android imageview
source share
1 answer

Thanks Nicola

 ViewCompat.setLayerType(view, LAYER_TYPE_HARDWARE, null) 

Correctly. It solves my problem like a charm.

Could you post your answer as an answer, Nicola? Therefore, I can rate you as the correct answer.

+1
source share

All Articles