我可以在 MapView 上的叠加层中使用 AnimationDrawable 吗?
我用 XML 创建了一个 AnimationDrawable,它工作得很好。但是,将可绘制对象作为覆盖标记移动到 MapView 中(替换工作正常的静态可绘制对象)时,动画顽固地拒绝播放。我将对 start() 的调用移至一个按钮,以进行测试,即使在显示 MapView 后按下几秒钟,动画也不会启动。我在 logcat 中没有看到任何内容。我知道在所有窗口设置完毕后需要调用 start() ,但这似乎是一个单独的问题。
AnimationDrawables 与 MapView 兼容吗?
我需要做一些特殊的事情才能在 MapView 中工作吗?
您曾经在 MapView 中成功完成过一项工作吗?
解决方案
使用 Matt 的解决方案(如下),我通过将 ImageView 放入 MapView 的图层中而不是使用覆盖层来添加 AnimationDrawable。
public void showAnimatedMarker(GeoPoint point) {
LinearLayout v = (LinearLayout) View.inflate(context, R.layout.markerlayout, null);
ImageView marker = (ImageView) v.findViewById(R.id.marker);
AnimationDrawable markerImage = (AnimationDrawable)marker.getDrawable();
this.addView(v, 0, new MapView.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT, point, MapView.LayoutParams.BOTTOM_CENTER));
markerImage.start();
}
然后是markerlayout.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/marker"
android:src="@drawable/my_animation_drawable"
/>
</LinearLayout>
I have created an AnimationDrawable in XML, and it works fine. But on moving the drawable into a MapView as an overlay marker (replacing a static drawable that works fine), the animation stubbornly refuses to play. I've moved the call to start() to a button, for testing, and even when pressed several seconds after the MapView has displayed, the animation doesn't start. I'm seeing nothing in logcat. I know start() needs calling after all the windows are set up, but this seems to be a separate issue.
Are AnimationDrawables compatible with MapView?
Is there something special I need to do to make one work in a MapView?
Have you ever successfully had one work in a MapView?
Solution
Using Matt's solution (below) I added the AnimationDrawable by putting the ImageView inside the MapView's layers, rather than using an overlay.
public void showAnimatedMarker(GeoPoint point) {
LinearLayout v = (LinearLayout) View.inflate(context, R.layout.markerlayout, null);
ImageView marker = (ImageView) v.findViewById(R.id.marker);
AnimationDrawable markerImage = (AnimationDrawable)marker.getDrawable();
this.addView(v, 0, new MapView.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT, point, MapView.LayoutParams.BOTTOM_CENTER));
markerImage.start();
}
And then markerlayout.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/marker"
android:src="@drawable/my_animation_drawable"
/>
</LinearLayout>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这未经动画测试,但可能有一定用处。
我在向 MapView 添加小部件时遇到问题,但找到了 addView 方法。尝试通过此方法添加 AnimationDrawable,它可能会改变 MapView 处理它的方式,从而正确地制作动画:
看看这里的一个小例子:
http://www.gauntface。 co.uk/pages/blog/2010/01/04/mapview-with-widgets-android/
This is untested with animations, but may be of some use.
I had issues with adding widgets to the MapView, but found the addView method. Try adding the AnimationDrawable through this method, it may change how it is treated by the MapView and hence animate correctly:
Have a look here for a tiny example:
http://www.gauntface.co.uk/pages/blog/2010/01/04/mapview-with-widgets-android/