简体   繁体   English

在Android中获取视图的alpha /不透明度

[英]Getting alpha/opacity of a View in Android

How can I get the alpha/opacity of a View after I've animated it? 在动画制作后,如何获得View的alpha / opacity?

My fadeIn() is below - fadeOut() is the same with the endpoints switched. 我的fadeIn()低于 - fadeOut()与切换的端点相同。

public void fadeIn(View view) {
    Animation animation = new AlphaAnimation(0.0f, 1.0f);
    animation.setDuration(1000);
    animation.setFillAfter(true);
    view.startAnimation(animation);
}

I would highly recommend you to define the animations in an XML-file. 我强烈建议您在XML文件中定义动画。 The API doesn't have support for getting a specific alpha. API不支持获取特定的alpha。

You can still have in mind that the opacity that your view has, is the last one you've defined; 您仍然可以记住,您的视图具有的不透明度是您定义的最后一个; in this case, (your fadeIn() method), your latest opacity value is the value you passed into the AlphaAnimation constructor. 在这种情况下,(您的fadeIn()方法),您的最新不透明度值是您传递给AlphaAnimation构造函数的值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM