Android Studio - 在 OnMarkerClick/OnInfoWindowClick 之后显示新布局

Android Studio - Display New Layout after OnMarkerClick/OnInfoWindowClick

我目前正在使用 Android Studio 开发我的地图应用程序,我想在按下标记或地图上标记上方的信息 window 后显示特定布局。如何将其添加到我的代码中?提前致谢!!

这是我准备的布局代码:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/ic_infobg">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:id="@+id/addressTV"
        android:layout_alignParentTop="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="false"
        android:layout_marginLeft="26dp"
        android:layout_marginStart="26dp"
        android:layout_marginTop="82dp"
        android:singleLine="true"
        android:layout_marginRight="26dp"
        android:text="Address: " />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:text="Lot No.: "
        android:id="@+id/lotnumTV"
        android:layout_below="@+id/addressTV"
        android:layout_alignLeft="@+id/addressTV"
        android:layout_alignStart="@+id/addressTV"
        android:layout_marginTop="28dp" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:text="Area: "
        android:id="@+id/areaTV"
        android:layout_below="@+id/lotnumTV"
        android:layout_alignLeft="@+id/lotnumTV"
        android:layout_alignStart="@+id/lotnumTV"
        android:layout_marginTop="5dp" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:text="Utilities: "
        android:id="@+id/utilTV"
        android:layout_below="@+id/areaTV"
        android:layout_alignLeft="@+id/areaTV"
        android:layout_alignStart="@+id/areaTV"
        android:layout_marginTop="5dp" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:text="Accessibility: "
        android:id="@+id/accsTV"
        android:layout_below="@+id/utilTV"
        android:layout_alignLeft="@+id/utilTV"
        android:layout_alignStart="@+id/utilTV"
        android:layout_marginTop="5dp" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:text="ASSESSMENT"
        android:id="@+id/assTV"
        android:layout_below="@+id/accsTV"
        android:layout_alignLeft="@+id/accsTV"
        android:layout_alignStart="@+id/accsTV"
        android:layout_marginTop="22dp"
        android:textStyle="bold" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:text="Commercial/Industrial/Residential Lot"
        android:id="@+id/typeTV"
        android:layout_below="@+id/assTV"
        android:layout_alignLeft="@+id/assTV"
        android:layout_alignStart="@+id/assTV" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:text="Owner: "
        android:id="@+id/ownerTV"
        android:layout_marginTop="102dp"
        android:layout_below="@+id/typeTV"
        android:layout_alignLeft="@+id/typeTV"
        android:layout_alignStart="@+id/typeTV" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:text="Cellphone No.: "
        android:id="@+id/cpnumTV"
        android:layout_below="@+id/owneraddTV"
        android:layout_alignLeft="@+id/owneraddTV"
        android:layout_alignStart="@+id/owneraddTV"
        android:layout_marginTop="6dp" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:text="Telephone No.: "
        android:id="@+id/telnumTV"
        android:layout_below="@+id/cpnumTV"
        android:layout_alignLeft="@+id/cpnumTV"
        android:layout_alignStart="@+id/cpnumTV"
        android:layout_marginTop="6dp" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:text="Address: "
        android:id="@+id/owneraddTV"
        android:layout_below="@+id/ownerTV"
        android:layout_alignLeft="@+id/ownerTV"
        android:layout_alignStart="@+id/ownerTV"
        android:layout_marginTop="6dp" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:text="E-mail Address: "
        android:id="@+id/emailTV"
        android:layout_below="@+id/telnumTV"
        android:layout_alignLeft="@+id/telnumTV"
        android:layout_alignStart="@+id/telnumTV"
        android:layout_marginTop="6dp" />
</RelativeLayout>

这是我的 java 地图文件:

public class MapFragment extends FragmentActivity implements OnMapReadyCallback
{
    private SupportMapFragment sMapFragment;

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

        sMapFragment = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map);
        sMapFragment.getMapAsync(this);
    }

    @Override
    public void onMapReady(GoogleMap mMap)
    {
        LatLng one = new LatLng(10.7187530, 122.5611620);
        LatLng ILOILO = new LatLng(10.730278, 122.548889);

        mMap.setBuildingsEnabled(true);
        mMap.setMyLocationEnabled(true);
        mMap.setMapType(GoogleMap.MAP_TYPE_TERRAIN);
        mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(ILOILO, 12));

        mMap.addMarker(new MarkerOptions()
            .title("Empty Lot 1")
            .snippet("blah blah blah")
            .position(one)
            .icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_AZURE)));
    }
}

只需实现一个OnMarkerClickListener接口并调用setContentView

public class MapFragment extends FragmentActivity implements 
        GoogleMap.OnMapLoadedCallback, GoogleMap.OnMarkerClickListener {

    ...

    @Override
    public void onMapReady(GoogleMap mMap) {
        ...
        // Set a marker click listener
        mMap.setOnMarkerClickListener(this);
    }

    @Override
    public boolean onMarkerClick(Marker marker) {
        // Use a specific layout (some_layout.xml) for this activity
        setContentView(R.layout.some_layout);

        return false;
    }