Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9208241
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T00:34:28+00:00 2026-06-18T00:34:28+00:00

I have several fragments within one Activity. I am trying to make my app

  • 0

I have several fragments within one Activity.

I am trying to make my app compatible with both small and large screens.

I have created a main layout with a LinearLayout as the root. This LinearLayout contains two FrameLayouts. One FrameLayout is used to store Fragments which will store lists or any other side details. I only want this to be in view when specific buttons are pressed.

The other FrameLayout is used to display the main part of the app (a map) which is in its own fragment.

To begin with I add my main map fragment using:

FragmentManager fm = getSupportFragmentManager();
FragmentTransaction ft = fm.beginTransaction();

ft.add(R.id.viewer, viewModeFragment);
ft.commit();

When I want the side panel to appear with a list fragment I call something like this:

            FrameLayout fl = (FrameLayout)findViewById(R.id.list);
            fl.setVisibility(View.VISIBLE);

            FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
            ft.add(R.id.list, editOsmInfoFragment);
            ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
            ft.addToBackStack(null);
            ft.show(editOsmInfoFragment);
            ft.commit();

Here is my XML file for the main Activity layout:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/myFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >

    <FrameLayout
        android:id="@+id/list"
        android:name="com.srose.cyclopathed.view.LoadRoutesFragment"
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:visibility="gone"/>

    <FrameLayout
        android:id="@+id/viewer"
        android:name="com.srose.cyclopathed.view.ViewModeFragment"
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="2" />    
</LinearLayout> 

This seems to work some what ok but the main problem is that if I use the app on the tablet and the side bar appears with a list fragment contained within it, if the back button is pressed the fragment vanishes as expected but the blank list FrameLayout remains on screen because it was not part of the transaction.

I guess I am not using this properly but I have no idea how to implement it so that the whole side bar whole slide to the left in the back button is pressed.

Can anyone please help?
Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T00:34:29+00:00Added an answer on June 18, 2026 at 12:34 am

    Do not explicitly set the visibility on R.id.list.

    In your layout XML, remove the android:visiblility attribute on R.id.list FrameLayout to make it visible. Since this FrameLayout is initially empty, it will not show up on screen. When the side panel is added to it programmatically via the FragmentTransaction, you will see it, and when it is removed (via the back button), it will go away. You must call FrameLayout# setConsiderGoneChildrenWhenMeasuring() in order for the layout to collapse when the Fragment is removed.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In my app, I have only one Activity which hosts several fragments . The
I have a App with several Fragments which are managed by one Activity. My
I have an activity which is a container for several fragments. One of the
In my application, I have the Activity and several Fragments (Activity works as Controller
I have Activity with ViewPager that contains several Fragments. I am also using drop-down
I have a several activities in my app. The main activity (activity1) extends ActivityGroup
I have an activity with several fragments. In that activity I want to be
I have a FragmentActivity using a ViewPager to serve several fragments. Each is a
We have several offices around the US and one in India. Our IT department
I've got a Wix project made up of several fragments. One of those fragments

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.