Setting view alpha in runtime is slow, how to speed it up?

狂风中的少年 提交于 2019-12-08 07:21:17

问题


I have two ImageViews which I hope imageViewA is overlapped by imageViewB, and when user select a seekbar, the alpha value of imageViewB will change accordingly (e.g., becoming translucent and users can see part of imageViewA).

It supposes to be a easy coding task, however I found the performance is VERY slow in my Galaxy S6.

I have tried all setAlpha(int), setAlpha(float), and setImageAlpha(float), but get no hope. It seems the most related question post is App UI operations (setting alpha, setting margins, etc.) very slow on 4.4.4 compared to 4.0.3

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

---- Here is some updates ----

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

imageViewB.setAlpha(selectedAlphaValue);

The VERY slow means the fps is less than 1~2. I do hope I can get the alpha changed 10 times a second to make users feel comfortable. (BTW, I don't benchmark the delay of set alpha function because it is TOO SLOW, even my human eyes can notice it only changes 1~2 times per second)


回答1:


Thanks Nikola,

ViewCompat.setLayerType(view, LAYER_TYPE_HARDWARE, null)

Is the right thing to do. It solve my problem like a charm.

Could you please post your reply as an answer, Nikola? So I can rate you as the correct answer.



来源:https://stackoverflow.com/questions/37601314/setting-view-alpha-in-runtime-is-slow-how-to-speed-it-up

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!