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; } }
太感謝你了! – Yeray