如何设置视图/列表视图行的不透明度/透明度
在我的代码中,我对每一行内容都有状态,因此在列表视图中,如果行的状态为已读,我需要以不透明度/透明度显示它,但对于视图,没有直接方法来设置 alpha。
if(termDetails.getInt("isRead") > 0) {
AlphaAnimation animation = new AlphaAnimation(1, 0.2f);
animation.setFillAfter(true);
rowView.setAnimation(animation);
} else {
AlphaAnimation animation = new AlphaAnimation(1, 1);
animation.setFillAfter(true);
rowView.setAnimation(animation);
}
上面的代码可以工作,但它不稳定,当你滚动列表时它会失去一致性。
In my code i have state for each row of content so in list view if row has state as read, i need to display it with opacity/ transparency but for the view there is no direct method to set alpha.
if(termDetails.getInt("isRead") > 0) {
AlphaAnimation animation = new AlphaAnimation(1, 0.2f);
animation.setFillAfter(true);
rowView.setAnimation(animation);
} else {
AlphaAnimation animation = new AlphaAnimation(1, 1);
animation.setFillAfter(true);
rowView.setAnimation(animation);
}
Above code works but it is unstable as u scroll through list it looses the consistency.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试在您的 xml 文件中使用它,您想要透明的部分将是......
Try using this in your xml file where the part you want transparent will be...
在 Android 中,颜色被称为 #AARRGGBB,其中
A - Alpha
R-红色,
G——绿色,
B - 蓝色
,每个分量在 00 - FF 之间变化。在 Alpha 的情况下,00 是透明的,而 FF 是 100% 不透明度。
将想要透明的项目的背景设置为#00RRGGBB
In Android, the colors are mentioned as #AARRGGBB where
A - Alpha
R - Red,
G - Green,
B - Blue
and each component varies between 00 - FF. In the case of Alpha, 00 is transparent while FF is 100% opacity.
Set the background of the item that you want to be transparent as #00RRGGBB