Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

To alternate between using the Google Map fragment and VideoView within a single Activity, you can use a layout that contains both views and switch between them programmatically.

Here's an example of how to do this:

  1. Create a layout file that contains both the Google Map fragment and VideoView. You can use a LinearLayout or RelativeLayout to arrange the two views as needed.
<RelativeLayout
    android:id="@+id/map_container"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <fragment
        android:id="@+id/map_fragment"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        class="com.google.android.gms.maps.SupportMapFragment" />

    <VideoView
        android:id="@+id/video_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:visibility="gone" />
</RelativeLayout>
  1. In your Activity's onCreate() method, initialize both views and set up any necessary callbacks or listeners:
private SupportMapFragment mapFragment;
private VideoView videoView;

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

    // Initialize the map fragment and video view
    mapFragment = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map_fragment);
    videoView = findViewById(R.id.video_view);

    // Set up any necessary callbacks or listeners here
}
  1. To switch between the two views, you can simply set the visibility of one view to "VISIBLE" and the other to "GONE". This can be done in response to user input or other events in your app:
// Show the map view and hide the video view
mapFragment.getView().setVisibility(View.VISIBLE);
videoView.setVisibility(View.GONE);

// Show the video view and hide the map view
mapFragment.getView().setVisibility(View.GONE);
videoView.setVisibility(View.VISIBLE);

By switching the visibility of the two views programmatically, you can alternate between using the Google Map fragment and VideoView as needed in your app.