我可以在一个图形页面使用AnimationDrawable在覆盖?图形、页面、AnimationDrawable

2023-09-06 03:06:14 作者:各自安好

我已经创建了XML的AnimationDrawable,并能正常工作。但在移动可绘制成图形页面作为覆盖标记(更换静态的绘制工作正常),动画顽固地拒绝播放。我搬到了调用start(),以一个按钮,用于测试,即使pressed几秒钟的MapView已经显示后,动画将不会启动。我看到没有在logcat中。我知道开始()需要调用后,所有的窗户都设置了,但是这似乎是一个单独的问题。

是AnimationDrawables与MapView的兼容?

有没有我需要做的,使在一个图形页面一部作品一些特别的东西?

你曾经成功有一个工作在图形页面?

解决方案

使用马特的解决方案(下)我加了AnimationDrawable通过将ImageView的的MapView的层内,而不是使用的叠加。

 公共无效showAnimatedMarker(的GeoPoint点){
    的LinearLayout V =(的LinearLayout)View.inflate(背景下,R.layout.markerlayout,NULL);
    ImageView的标记=(ImageView的)v.findViewById(R.id.marker);
    AnimationDrawable markerImage =(AnimationDrawable)marker.getDrawable();
    this.addView(V,0,新MapView.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,ViewGroup.LayoutParams.WRAP_CONTENT,点,MapView.LayoutParams.BOTTOM_CENTER));
    markerImage.start();
}
 

然后markerlayout.xml:

 < XML版本=1.0编码=UTF-8&GT?;
< LinearLayout中的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    机器人:layout_width =WRAP_CONTENT
    机器人:layout_height =WRAP_CONTENT
    >
    < ImageView的
            机器人:layout_width =WRAP_CONTENT
            机器人:layout_height =WRAP_CONTENT
            机器人:ID =@ + ID /标记
            机器人:SRC =@可绘制/ my_animation_drawable
    />
< / LinearLayout中>
 

解决方案 包括江西,10省明确 今年这道高考6分题,单选A或B都算对

这是未经测试与动画,但可能是一些使用。

我有问题,将小工具添加到图形页面,却发现addView方法。尝试通过这种方法加入AnimationDrawable,它可能会改变它是如何的MapView处理,因此正确的动画

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

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>

解决方案

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/