Ask Your Question
1

How can I alternate between using the Google Map fragment and VideoView within a single Activity?

asked 2021-04-13 11:00:00 +0000

woof gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
3

answered 2022-08-09 21:00:00 +0000

djk gravatar image

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.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2021-04-13 11:00:00 +0000

Seen: 9 times

Last updated: Aug 09 '22