0

我是一個新手和Android開發人員。我的目標是在谷歌地圖V2 API android中的定製信息窗口中運行視頻。我知道如何在視圖內運行視頻(通過加載一系列圖像,使它們看起來像電影)。我還學會了如何在定製的infowindow中加載圖像。我正在嘗試在infowindow中放映圖像幻燈片。但問題是隻有第一個圖像被加載。除非另有說明,否則我再次單擊標記,infoWindow內容不會更新。我附上下面如何在Google Maps V2上的自定義InfoWindow中創建圖像幻燈片放映 - Android API

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) 

我試圖調用showInfoWindow()標記對象它傳遞給getInfoContents中的updateUI函數。 我在做什麼錯了什麼是什麼正確的方式來調用infoWindow裏面的imageView獲取新圖像後的showInfo窗口?

回答

4

我的目標是在谷歌定製的信息窗口中運行的視頻映射V2 API的Android

這是不可能的,對不起。包括其信息窗口的地圖由另一個進程(運行Play Services Framework的進程)渲染。它無法處理動畫,更不用說視頻了。

但問題是隻有第一個圖像正在加載。

正確。

歡迎您再次撥打電話showInfoWindow()Marker,觸發它再次撥打您的InfoWindowAdapter,在那裏您可以按順序顯示下一張圖片,並查看是否可以令您滿意。

+0

感謝您的答覆非常有用的。我正在嘗試使用標記對象參數在getInfoContents(標記標記)函數內部調用showInfoWindow()。但我正在getInfoContents裏面的行中獲取android.view.InflateException,我再次加載視圖。 –

+0

@ArunGK:在您的問題中發佈您的修改後的代碼和堆棧跟蹤。 – CommonsWare

+0

對不起,由於空間限制,我不能粘貼整個代碼。雖然我只添加了一行,但在上面的粘貼代碼中,在updateUI(Marker markerShowingInfoWindow)函數中,在設置圖像資源後,我添加了以下幾行:if(markerShowingInfoWindow!= null && true){ markerShowingInfoWindow。showInfoWindow(); }' –

3

我被困在一個類似的問題上,我通過關閉infowindow並再次顯示,解決了這個問題,這兩個事件之間的時間甚至沒有發出閃爍。 我還添加了緩存陣列。 我發現這個鏈接解決我自己的問題Link

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(); 
     } 
    } 
} 
相關問題