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

  • SEARCH
  • Home
  • 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 8320993
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T22:51:48+00:00 2026-06-08T22:51:48+00:00

For large screens I have two fragments, they shall be either top/bottom or left/right.

  • 0

For large screens I have two fragments, they shall be either top/bottom or left/right. The problem is that one fragment is taking (almost) all space is taking up by one fragment. For my activity I have two main.xml (one for portrait one for landscape). But they are basically similar (apart from orientation).

main.xml

<?xml version="1.0" encoding="utf-8"?>
 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="fill_parent"
  android:layout_height="wrap_content"
  android:orientation="vertical" android:id="@+id/frag_cont" >
 </LinearLayout>

In onCreate I add my fragments to that layout:

public void onCreate(Bundle savedInstanceState) 
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    OverviewFragment of = new OverviewFragment();
    FragmentTransaction tof = getFragmentManager().beginTransaction();
    tof.add(R.id.frag_cont, of);
    DetailFragmentInitial df = new DetailFragmentInitial();
    tof.add(R.id.frag_cont, df);
    tof.commit();

}

The two fragments look kind of similar in terms of onCreateView()

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) 
{   
    return inflater.inflate(R.layout.overview, container, false);

}

Finally the two xml files for these fragments look like this, first the smaller fragment:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" android:layout_weight="1">


<ImageView
    android:id="@+id/imageLogo"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:src="@drawable/logo"
    android:layout_centerInParent="true" />

    <TextView
    android:id="@+id/textB"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="text"
    android:layout_above="@id/imageLogo" 
    android:layout_centerHorizontal="true"/>
</RelativeLayout>

And now the greedy one taking the space:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"  
android:layout_weight="10000" >

 <ListView
    android:id="@+id/ListView01"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content" >
 </ListView>

</LinearLayout>

I assumed that when I set both layout_weight to 1 then both will take the same amount of space, but even with the setting 1000:1 the bigger one takes about 2/3 of the space. Leaving the weight away will give the bigger fragment all the screen and the other one is not visiable at all. Any ideas?

Edit:

I followed the approach given below. Much better now in terms of space. On screen rotate the overview fragment (basically list view) is empty, the other fragment is still okay.

In OverviewFragment.java I repopulate the fragment in onActivityCreated():

public void onSaveInstanceState(Bundle bundle)
{
    bundle.putSerializable("list", mList);
    super.onSaveInstanceState(bundle);
}

@Override
public void onActivityCreated(Bundle savedInstanceState) 
{
     super.onActivityCreated(savedInstanceState);

    if(savedInstanceState != null)
    {
        mList = (ArrayList<myObject>) savedInstanceState.getSerializable("list");
    }
    else
    {
        mAppList = new ArrayList<myObject>();
        new getApps().execute();
    }

    ListView lv = (ListView) getActivity().findViewById(R.id.ListView01);
    lv.setOnItemClickListener(new TableItemSelected());
    mItemAdapter = new ItemAdapterOverview(getActivity().getApplicationContext(), mList);
    lv.setAdapter(mItemAdapter);
}

when rotating the screen the onSaveInstanceState() is called first and then onActivityCreated() twice. The first call the saveInstanceState is not null, the second time it is. Anyway in both cases I should see my list, either build up from scratch or the saved list. Why isn’t it and why is that method called twice?

  • 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-08T22:51:50+00:00Added an answer on June 8, 2026 at 10:51 pm

    Not entirely sure whether this will be causing your issue (I suspect it does), but using FragmentTransaction.add(..) doesn’t add the Fragment into the container, it essentially replaces the container with that Fragment. The issue here is that you’re adding both Fragments to the same container so they will take up the same space and cause issues.

    A better way to do this would be to add two container views into your frag_cont LinearLayout (e.g. FrameLayouts), and give them two separate ids (e.g. frag_one and frag_two). Then in your onCreate(..), change it to read:

    FragmentTransaction tof = getFragmentManager().beginTransaction();
    tof.add(R.id.frag_one, of);
    DetailFragmentInitial df = new DetailFragmentInitial();
    tof.add(R.id.frag_two, df);
    tof.commit();
    

    This will make it so that the layout with id frag_one is filled by the OverviewFragment and the one with id frag_two replaced by the DetailFragmentInitial. You can then use the views in main.xml to tweak the sizes of the fragments as you see fit.

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

Sidebar

Related Questions

So it's possible to align the top, bottom, left, and right of one view
I have two different sized images, one if for screens smaller than 759px, the
I have a screen that is supposed to have a few large sections of
My current setup has one large monitor and one smaller monitor. I have VS
I have an application with a large number of buttons across the various screens.
I'm building an application that have to work on small screens (1024*768) or higher
I have an application in which there are two buttons side-by-side at the bottom
I have a tricky problem related to synchronized scrolling of two different views. I've
I have a WPF TabControl with a large number of tabs and they are
Im bulding a web application , i have a two set fluid layout one

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.