本文介绍了设置布局阿尔法/不透明度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有可能设置和获取布局的阿尔法/不透明度和它所有的子视图?我不是在谈论的背景。说视频控件,如播放,暂停和进度的集合在一个相对布局。

Is it possible to set and get the Alpha/Opacity of a Layout and all it's child views? I'm not talking about the background. Say a collection of Video Controls like Play, Pause and Progressbar in a Relative Layout.

我可以用动画来淡入淡出,但想知道是否有一个直接的方法,我可以用。

I can use animation to fade in and out but wanted to know if there was a direct method I could use.

推荐答案

您可以设置布局中的α和它的孩子(或任何其他观点的这个问题)使用AlphaAnimation 0的持续时间和setFillAfter选项。

You can set the alpha on the layout and it's children (or any other view for that matter) using AlphaAnimation with 0 duration and setFillAfter option.

例如:

AlphaAnimation alpha = new AlphaAnimation(0.5F, 0.5F);
alpha.setDuration(0); // Make animation instant
alpha.setFillAfter(true); // Tell it to persist after the animation ends
// And then on your layout
yourLayout.startAnimation(alpha);

您可以使用一个动画的多个组件,以节省内存。做复位()再次使用,或者clearAnimation()下跌阿尔法。

You can use one animation for multiple components to save memory. And do reset() to use again, or clearAnimation() to drop alpha.

虽然它看起来粗糙,遭到黑客攻击它实际上是一个很好的方式来设置α对集半岛的看法,这并不需要太多的内存和处理器时间。

Though it looks crude and hacked it's actually a good way to set alpha on set ov views that doesn't take much memory or processor time.

不知道有关获取当前alpha值虽然。

Not sure about getting current alpha value though.

这篇关于设置布局阿尔法/不透明度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-11 16:19