在运行时设置视图alpha很慢,如何加快速度? [英] Setting view alpha in runtime is slow, how to speed it up?

查看:164
本文介绍了在运行时设置视图alpha很慢,如何加快速度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个ImageViews,我希望imageViewA与imageViewB重叠,当用户选择一个搜索栏时,imageViewB的alpha值会相应改变(例如,变为半透明,用户可以看到imageViewA的一部分)。

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).

它假设是一个简单的编码任务,但我发现我的Galaxy S6的性能非常慢。

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

我已经尝试了所有setAlpha(int),setAlpha(float)和setImageAlpha(float),但没有希望。似乎最相关的问题是应用程序UI操作(设置alpha,设置边距等)在4.4.4与4.0.3相比非常慢

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);

极慢表示fps小于1~2。我希望我可以每秒更换10次alpha,让用户感觉舒服。 (顺便说一下,我没有基准设置alpha函数的延迟,因为它太慢了,即使我的人眼也注意到它每秒只会改变1~2次)

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)

推荐答案

谢谢Nikola,

ViewCompat.setLayerType(view, LAYER_TYPE_HARDWARE, null)

这是正确的做法。它像魅力一样解决了我的问题。

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

你能否回复一下你的回答,Nikola?所以我可以评价你是正确的答案。

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

这篇关于在运行时设置视图alpha很慢,如何加快速度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆