是否可以在 Android 中对布局(RelativeLayout
、LinearLayout
等)的背景图像进行动画处理?在我的一个应用程序中,我从互联网获取图像并在加载后将其显示为背景图像。如果使用淡入淡出效果或类似的效果来替换背景图像,那就太酷了。
我已经尝试了很多,但似乎无法找到解决方案。动画始终是布局而不是图像本身。
Is it possible to animate the background image of a layout (RelativeLayout
, LinearLayout
, etc.) in Android? In one of my applications I am fetching an image from the internet and displaying it as the background image once it's loaded. It would be really cool if the background image was swapped out using a fade effect or something like that.
I've tried quite a bit, but couldn't seem to find a solution. It's always the layout that's animating and not the image itself.
发布评论
评论(1)
可能是最好的选择,将布局放在
FrameLayout
或RelativeLayout
中,并使用 ViewSwitcher 位于其后面。请参阅演示 (以及相关布局)在 Android API 演示应用程序中(使用 ImageSwitcher,它是ViewSwitcher
的基于适配器的特殊子类)。它确实意味着您的应用程序中有一个额外的ViewGroup
级别,但除非您正在做一些特别复杂的事情(将它们嵌套在ListView
行或其他内容中),否则它应该表现得很好,并且为您处理过渡动画。您也可以使用 DroidFu 的 ">WebImageView,它为您完成了大部分烦人的跑腿工作。
Might be your best bet to just layer your layout in a
FrameLayout
orRelativeLayout
with a ViewSwitcher behind it. See the demo (and related layouts) in the Android API Demos app (that uses an ImageSwitcher, which is a special-case adapter-based subclass ofViewSwitcher
). It does mean an extraViewGroup
level in your app, but unless you're doing something especially complicated (nesting these inListView
rows or something) it should perform just fine, and handles the transition animations for you.You could also just use WebImageView from DroidFu, which does most of the annoying legwork for you.