0

我是一个新手wrt android开发。我的目标是在 google maps V2 API android 的自定义信息窗口中运行视频。我知道如何使视频在视图中运行(通过加载一系列图像使它们看起来像电影)我还学习了如何在自定义信息窗口中加载图像。我正在尝试在信息窗口中显示图像幻灯片。但问题是只有第一个图像被加载。除非我再次单击标记,否则 infoWindow 内容不会更新。我在下面附上我的代码

main_activity.java

public class BasicMapActivity extends FragmentActivity {
   private GoogleMap mMap;
   static final LatLng MELBOURNE = new LatLng(-37.81319, 37.00);
   public static LatLng argOut = null;
   public static String msg = "1";

   private static ImageView imageView;
   int i=0;
   int imgid[]={R.drawable.a,R.drawable.b,R.drawable.c,R.drawable.d};
   RefreshHandler refreshHandler=new RefreshHandler();

   class RefreshHandler extends Handler{
       @Override
       public void handleMessage(Message msg) {
        BasicMapActivity.this.updateUI(null);
       }
       public void sleep(long delayMillis){
           this.removeMessages(0);
           sendMessageDelayed(obtainMessage(0), delayMillis);
       }
   };

  public void updateUI(Marker markerShowingInfoWindow){
        refreshHandler.sleep(2000);
        if(i<imgid.length){
            imageView.setImageResource(imgid[i]);
            if (markerShowingInfoWindow != null && true) {
                markerShowingInfoWindow.showInfoWindow();
            } 
            i++;
          }
   }


@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.basic_demo);
    setUpMapIfNeeded();
}

@Override
protected void onResume() {
    super.onResume();
    setUpMapIfNeeded();
}


private void setUpMapIfNeeded() {
    if (mMap == null) {
        mMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map))
                .getMap();
        if (mMap != null) {
            setUpMap();
        }
    }
}

private void setUpMap() {

    Marker melbourne = mMap.addMarker(new MarkerOptions()
    .position(MELBOURNE)
    .title("Melbourne")
    .snippet("Population: 4,137,400"));

   // when a infowindow is tapped (infowindow open request)
    mMap.setInfoWindowAdapter(new InfoWindowAdapter() {
        @Override
        public View getInfoWindow(Marker arg0) {
            return null;
        }

        @Override
        public View getInfoContents(Marker arg0) {
            String test = arg0.getTitle();
            View v = getLayoutInflater().inflate(R.layout.windowlayout, null);
            imageView = (ImageView) v.findViewById(R.id.imageView1);
            imageView.setVisibility(View.VISIBLE);
            if(!test.equalsIgnoreCase("Melbourne")){
                 updateUI(arg0);
            } else {
                imageView.setImageDrawable(getResources().getDrawable(R.drawable.badge_wa));
            }

            return v;
        }
    });

}

}

ErrorStackTrace 如下:

11-03 13:58:19.000: E/AndroidRuntime(5095): FATAL EXCEPTION: main
11-03 13:58:19.000: E/AndroidRuntime(5095): java.lang.StackOverflowError
11-03 13:58:19.000: E/AndroidRuntime(5095):     at java.util.ArrayList.<init>(ArrayList.java:81)
11-03 13:58:19.000: E/AndroidRuntime(5095):     at java.lang.Throwable.<init>(Throwable.java:66)
11-03 13:58:19.000: E/AndroidRuntime(5095):     at java.lang.Throwable.<init>(Throwable.java:108)
11-03 13:58:19.000: E/AndroidRuntime(5095):     at java.lang.Exception.<init>(Exception.java:60)
11-03 13:58:19.000: E/AndroidRuntime(5095):     at java.lang.reflect.InvocationTargetException.<init>(InvocationTargetException.java:50)
11-03 13:58:19.000: E/AndroidRuntime(5095):     at java.lang.reflect.Constructor.constructNative(Native Method)
11-03 13:58:19.000: E/AndroidRuntime(5095):     at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
11-03 13:58:19.000: E/AndroidRuntime(5095):     at android.view.LayoutInflater.createView(LayoutInflater.java:586)
11-03 13:58:19.000: E/AndroidRuntime(5095):     at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
11-03 13:58:19.000: E/AndroidRuntime(5095):     at android.view.LayoutInflater.onCreateView(LayoutInflater.java:653)
11-03 13:58:19.000: E/AndroidRuntime(5095):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:678)
11-03 13:58:19.000: E/AndroidRuntime(5095):     at android.view.LayoutInflater.inflate(LayoutInflater.java:466)
11-03 13:58:19.000: E/AndroidRuntime(5095):     at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
11-03 13:58:19.000: E/AndroidRuntime(5095):     at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
11-03 13:58:19.000: E/AndroidRuntime(5095):     at com.example.mapdemo.BasicMapActivity$1.getInfoContents(BasicMapActivity.java:123)
11-03 13:58:19.000: E/AndroidRuntime(5095):     at com.google.android.gms.maps.GoogleMap$10.g(Unknown Source)
11-03 13:58:19.000: E/AndroidRuntime(5095):     at com.google.android.gms.maps.internal.d$a.onTransact(Unknown Source)
11-03 13:58:19.000: E/AndroidRuntime(5095):     at android.os.Binder.transact(Binder.java:297)
11-03 13:58:19.000: E/AndroidRuntime(5095):     at bnw.b(SourceFile:112)
11-03 13:58:19.000: E/AndroidRuntime(5095):     at maps.ag.bm.a(Unknown Source)
11-03 13:58:19.000: E/AndroidRuntime(5095):     at maps.ag.bm.b(Unknown Source)
11-03 13:58:19.000: E/AndroidRuntime(5095):     at maps.ag.bn.g(Unknown Source)
11-03 13:58:19.000: E/AndroidRuntime(5095):     at bqt.onTransact(SourceFile:145)
11-03 13:58:19.000: E/AndroidRuntime(5095):     at android.os.Binder.transact(Binder.java:297)
11-03 13:58:19.000: E/AndroidRuntime(5095):     at com.google.android.gms.maps.model.internal.d$a$a.showInfoWindow(Unknown Source)
11-03 13:58:19.000: E/AndroidRuntime(5095):     at com.google.android.gms.maps.model.Marker.showInfoWindow(Unknown Source)
11-03 13:58:19.000: E/AndroidRuntime(5095):     at com.example.mapdemo.BasicMapActivity.updateUI(BasicMapActivity.java:74)
11-03 13:58:19.000: E/AndroidRuntime(5095):     at com.example.mapdemo.BasicMapActivity$1.getInfoContents(BasicMapActivity.java:127)
11-03 13:58:19.000: E/AndroidRuntime(5095):     at com.google.android.gms.maps.GoogleMap$10.g(Unknown Source)
11-03 13:58:19.000: E/AndroidRuntime(5095):     at com.google.android.gms.maps.internal.d$a.onTransact(Unknown Source)
11-03 13:58:19.000: E/AndroidRuntime(5095):     at android.os.Binder.transact(Binder.java:297)
11-03 13:58:19.000: E/AndroidRuntime(5095):     at bnw.b(SourceFile:112)
11-03 13:58:19.000: E/AndroidRuntime(5095):     at maps.ag.bm.a(Unknown Source)
11-03 13:58:19.000: E/AndroidRuntime(5095):     at maps.ag.bm.b(Unknown Source)
11-03 13:58:19.000: E/AndroidRuntime(5095):     at maps.ag.bn.g(Unknown Source)
11-03 13:58:19.000: E/AndroidRuntime(5095):     at bqt.onTransact(SourceFile:145)
11-03 13:58:19.000: E/AndroidRuntime(5095):     at android.os.Binder.transact(Binder.java:297)
11-03 13:58:19.000: E/AndroidRuntime(5095):     at com.google.android.gms.maps.model.internal.d$a$a.showInfoWindow(Unknown Source)
11-03 13:58:19.000: E/AndroidRuntime(5095):     at com.google.android.gms.maps.model.Marker.showInfoWindow(Unknown Source)
11-03 13:58:19.000: E/AndroidRuntime(5095):     at com.example.mapdemo.BasicMapActivity.updateUI(BasicMapActivity.java:74)
11-03 13:58:19.000: E/AndroidRuntime(5095):     at com.example.mapdemo.BasicMapActivity$1.getInfoContents(BasicMapActivity.java:127)
11-03 13:58:19.000: E/AndroidRuntime(5095):     at com.google.android.gms.maps.GoogleMap$10.g(Unknown Source)
11-03 13:58:19.000: E/AndroidRuntime(5095):     at com.google.android.gms.maps.internal.d$a.onTransact(Unknown Source)
11-03 13:58:19.000: E/AndroidRuntime(5095):     at android.os.Binder.transact(Binder.java:297)
11-03 13:58:19.000: E/AndroidRuntime(5095):     at bnw.b(SourceFile:112)
11-03 13:58:19.000: E/AndroidRuntime(5095):     at maps.ag.bm.a(Unknown Source)
11-03 13:58:19.000: E/AndroidRuntime(5095):     at maps.ag.bm.b(Unknown Source)
11-03 13:58:19.000: E/AndroidRuntime(5095):     at maps.ag.bn.g(Unknown Source)
11-03 13:58:19.000: E/AndroidRuntime(5095):     at bqt.onTransact(SourceFile:145)
11-03 13:58:19.000: E/AndroidRuntime(5095):     at android.os.Binder.transact(Binder.java:297)
11-03 13:58:19.000: E/AndroidRuntime(5095):     at com.google.android.gms.maps.model.internal.d$a$a.showInfoWindow(Unknown Source)
11-03 13:58:19.000: E/AndroidRuntime(5095):     at com.google.android.gms.maps.model.Marker.showInfoWindow(Unknown Source)
11-03 13:58:19.000: E/AndroidRuntime(5095):     at com.example.mapdemo.BasicMapActivity.updateUI(BasicMapActivity.java:74)
11-03 13:58:19.000: E/AndroidRuntime(5095):     at com.example.mapdemo.BasicMapActivity$1.getInfoContents(BasicMapActivity.java:127)
11-03 13:58:19.000: E/AndroidRuntime(5095):     at com.google.android.gms.maps.GoogleMap$10.g(Unknown Source)
11-03 13:58:19.000: E/AndroidRuntime(5095):     at com.google.android.gms.maps.internal.d$a.onTransact(Unknown Source)
11-03 13:58:19.000: E/AndroidRuntime(5095):     at android.os.Binder.transact(Binder.java:297)
11-03 13:58:19.000: E/AndroidRuntime(5095):     at bnw.b(SourceFile:112)
11-03 13:58:19.000: E/AndroidRuntime(5095):     at maps.ag.bm.a(Unknown Source)
11-03 13:58:19.000: E/AndroidRuntime(5095):     at maps.ag.bm.b(Unknown Source)
11-03 13:58:19.000: E/AndroidRuntime(5095):     at maps.ag.bn.g(Unknown Source)
11-03 13:58:19.000: E/AndroidRuntime(5095):     at bqt.onTransact(SourceFile:145)
11-03 13:58:19.000: E/AndroidRuntime(5095):     at android.os.Binder.transact(Binder.java:297)
11-03 13:58:19.000: E/AndroidRuntime(5095):     at com.google.android.gms.maps.model.internal.d$a$a.showInfoWindow(Unknown Source)
11-03 13:58:19.000: E/AndroidRuntime(5095):     at com.google.android.gms.maps.model.Marker.showInfoWindow(Unknown Source)
11-03 13:58:19.000: E/AndroidRuntime(5095):     at com.example.mapdemo.BasicMapActivity.updateUI(BasicMapActivity.java:74)
11-03 13:58:19.000: E/AndroidRuntime(5095):     at com.example.mapdemo.BasicMapActivity$1.getInfoContents(BasicMapActivity.java:127)
11-03 13:58:19.000: E/AndroidRuntime(5095):     at com.google.android.gms.maps.GoogleMap$10.g(Unknown Source)
11-03 13:58:19.000: E/AndroidRuntime(5095):     at com.google.android.gms.maps.internal.d$a.onTransact(Unknown Source)

我正在尝试在传递给 getInfoContents 中的 updateUI 函数的标记对象上调用 showInfoWindow()。我在做什么错以及在 infoWindow 内的 imageView 获取新图像后调用 showInfo 窗口的正确方法是什么?

4

2 回答 2

4

我的目标是在 google maps V2 API android 的自定义信息窗口中运行视频

这是不可能的,对不起。地图(包括其信息窗口)由另一个进程(运行 Play 服务框架的进程)呈现。它无法处理动画,更不用说视频了。

但问题是只有第一个图像被加载。

正确的。

欢迎您showInfoWindow()再次Marker拨打电话,触发它InfoWindowAdapter再次拨打您的电话,您可以在其中按顺序显示下一张图片,看看是否满意。

于 2013-11-03T15:43:52.570 回答
3

我被困在一个类似的问题上,我通过关闭信息窗口并再次显示它来解决它,这两个事件之间的时间甚至没有闪烁。我还添加了一个缓存数组。我发现这个链接在解决我自己的问题时非常有用链接

public View getInfoContents(Marker marker) {
    View popup = contentsCache.get(marker.getId()); // cache array


        if(popup == null){
                contentsCache.put(marker.getId(), popup);
                popup = mInflater.inflate(R.layout.custom_info_contents, null);
                TextView tv=(TextView)popup.findViewById(R.id.title);
                tv.setText(marker.getTitle());
                ImageView i = (ImageView) popup.findViewById(R.id.img);
                Uri image=images.get(marker.getId());
                Log.i(TAG, marker.getId()+"");
                if (image != null) {
                    Picasso.with(mContext).load(image).placeholder(R.drawable.ic_launcher).into(i, new MarkerCallback(marker));
                }
        }       

    return popup;
}

MarkerCallback.java

public class MarkerCallback implements Callback {
    Marker marker=null;

    MarkerCallback(Marker marker) {
      this.marker=marker;

    }

    @Override
    public void onError() {
      Log.e(getClass().getSimpleName(), "Error loading thumbnail!");
    }

    @Override
    public void onSuccess() {
      if (marker != null && marker.isInfoWindowShown()) {
        marker.hideInfoWindow();
        marker.showInfoWindow();
      }
    }
}
于 2014-03-27T14:11:35.637 回答