我可以在MapView的叠加层中使用AnimationDrawable吗?

Oll*_*e C 6 android android-maps android-mapview

我用XML创建了一个AnimationDrawable,它工作正常.但是在将drawable移动到MapView作为叠加标记(替换一个工作正常的静态drawable)时,动画固执地拒绝播放.我已将调用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();
}
Run Code Online (Sandbox Code Playgroud)

然后是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>
Run Code Online (Sandbox Code Playgroud)

Mat*_*unt 3

这未经动画测试,但可能有一定用处。

我在向 MapView 添加小部件时遇到问题,但找到了 addView 方法。尝试通过此方法添加 AnimationDrawable,它可能会改变 MapView 处理它的方式,从而正确设置动画:

看看这里的一个小例子: http://www.gauntface.co.uk/pages/blog/2010/01/04/mapview-with-widgets-android/