设置布局的 Alpha/不透明度 [英] Set Alpha/Opacity of Layout

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

问题描述

是否可以设置和获取布局及其所有子视图的 Alpha/Opacity?我不是在谈论背景.假设有一组视频控件,例如相对布局中的播放、暂停和进度条.

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.

推荐答案

您可以使用具有 0 持续时间和 setFillAfter 选项的 AlphaAnimation 在布局及其子项(或任何其他视图)上设置 alpha.

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

您可以为多个组件使用一个动画以节省内存.并执行 reset() 以再次使用,或执行 clearAnimation() 以删除 alpha.

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

虽然它看起来很粗糙并且被黑了,但它实际上是一种在 set ov 视图上设置 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.

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

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