2014-01-21 24 views
0

在我的android应用程序中,我有一个谷歌地图v2内的地方标记片段。当我触摸标记时,它会显示带有标记名称的RelativeLayout。但是,当我触摸地图中的任何地方时,我会喜欢这个RelativeLayout隐藏。当我在地图中触摸时隐藏RelativeLayout

我的代码是这样的:

  • fragment_mapa.xml

    <fragment 
        android:id="@+id/map" 
        android:layout_width="match_parent" 
        android:layout_height="match_parent" 
        class="com.google.android.gms.maps.SupportMapFragment" 
        android:gravity="center" /> 
    
    
    <RelativeLayout 
        android:id="@+id/sliding_up" 
        android:layout_width="match_parent" 
        android:layout_height="100dp" 
        android:background="#fff" 
        android:orientation="vertical" 
        android:layout_alignParentBottom="true" 
        android:clickable="true" 
        android:focusable="false" 
        android:animateLayoutChanges="true" 
        android:visibility="invisible" > 
    
        <TextView 
          android:id="@+id/name" 
          android:layout_width="wrap_content" 
          android:layout_height="wrap_content" 
          android:layout_weight="1" 
          android:textSize="14sp" 
          android:gravity="center_vertical" 
          android:paddingLeft="10dp"/> 
    </RelativeLayout> 
    

  • 代码,其中它创建的标记物和方法的onClick显示RelativeLayout的

    public void addItemsToMap() { 
        appState.mapa.clear(); 
        if (appState.lista.isEmpty()) { 
         appState.readPlaces(5000, 0, appState.idCategoria); 
        } 
    
        appState.mapa.setOnMarkerClickListener(this); 
        appState.mapa.setOnInfoWindowClickListener(getInfoWindowClickListener()); 
    
    
        LatLng miPosicion = new LatLng(obtLatitud, obtLongitud); 
        appState.mapa.addMarker(new MarkerOptions() 
         .position(miPosicion) 
         .title("Mi posición") 
         .icon(BitmapDescriptorFactory.fromResource(R.drawable.location_icon))); 
    
        for (int i = 0; i < appState.lista.size(); i++) { 
         LatLng posItem = new LatLng(appState.lista.get(i).latitud,appState.lista.get(i).longitud); 
         appState.mapa.addMarker(new MarkerOptions() 
          .position(posItem) 
          .title(appState.lista.get(i).nombre) 
          .snippet(appState.lista.get(i).descripcion) 
          /*.icon(BitmapDescriptorFactory.fromResource(R.drawable.ic_launcher))*/); 
         Log.v("MAPA", "Marker " + i + ": " + appState.lista.get(i).nombre); 
        } 
    } 
    
    
    @Override 
    public boolean onMarkerClick(final Marker marker) { 
        if(marker != null) { 
         //marker.showInfoWindow(); 
         RelativeLayout slideLayout; 
         slideLayout = (RelativeLayout) findViewById(R.id.sliding_up); 
         slideLayout.setVisibility(View.VISIBLE); 
    
         Animation slide = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.slide_up); 
         slideLayout.startAnimation(slide); 
    
         TextView t; 
         t = (TextView) findViewById(R.id.name); 
         t.setText(marker.getTitle()); 
         return true; 
    
        } else { 
         RelativeLayout slideLayout; 
         slideLayout = (RelativeLayout) findViewById(R.id.sliding_up); 
         slideLayout.setVisibility(View.INVISIBLE); 
         return false; 
        } 
        } 
    

回答

1

//试试这个:

map.setOnMapClickListener(new OnMapClickListener() { 
     @Override 
     public void onMapClick(LatLng arg0) { 

     } 
    }); 
+0

太感谢你了! – Yeray

相关问题