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:
<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>
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
}
// 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.
Asked: 2021-04-13 11:00:00 +0000
Seen: 9 times
Last updated: Aug 09 '22