progrAmmar
progrAmmar

Reputation: 2670

Android Fragment doesn't show on Large Layout

I have created an application using Fragments to show List on the left and details on the right.

Following is my layout in layout-large Appointments.xaml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
       android:orientation="horizontal"
       android:layout_width="fill_parent"
       android:layout_height="fill_parent">
  <include
        android:id="@+id/cust_toolbar"
        layout="@layout/tool_bar" />
  <fragment 
    class="com.myapp.blue.Fragments.ListFragment"
    android:id="@+id/frg_list"
    android:layout_weight="1"
    android:layout_width="0px"
    android:layout_height="match_parent" />
  <FrameLayout
    android:id="@+id/frg_detail"
    android:layout_weight="1"
    android:layout_width="0px"
    android:layout_height="match_parent" />
</LinearLayout>

And this is the Appointments.xaml from layout Folder

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:background="#FFFFFFFF"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <include
        android:id="@+id/cust_toolbar"
        layout="@layout/tool_bar" />
    <fragment
        class="com.myapp.blue.Fragments.ListFragment"
        android:id="@+id/frg_list"
        android:layout_weight="1"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" />
</LinearLayout>

Here is the code for my Activity

public class AppointmentActivity : Activity
{

    protected override void OnCreate(Bundle savedInstanceState)
    {        
        base.OnCreate(savedInstanceState);
        //Set Content
        SetContentView(Resource.Layout.Appointments);        
        Toolbar toolbar = FindViewById<Toolbar>(Resource.Id.cust_toolbar);
        //Set Action bar
        SetActionBar(toolbar);
    }
}

The application runs flawlessly on Mobiles but when I run this application with Tablets None of my fragments show. I followed the instructions on this Xamarin walkthrough and have seen other stackoverflow posts where they say that the width should be 0px or dp. But I cannot get the list fragment to show up on my Tablet. What am I missing here?

Upvotes: 1

Views: 114

Answers (2)

Ishamael
Ishamael

Reputation: 12795

The problem is that the toolbar you include most likely has layout_width=match_parent, and as such occupies the entire linear layout with horizontal orientation. If you want your toolbar to be at the top, just make your linear layout vertical, and insert another horizontal linear layout inside with your fragments:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
       android:orientation="vertical"
       android:layout_width="fill_parent"
       android:layout_height="fill_parent">
  <include
        android:id="@+id/cust_toolbar"
        layout="@layout/tool_bar" />
  <LinearLayout 
       android:orientation="horizontal"
       android:layout_width="match_parent"
       android:layout_height="0dp"
       android:layout_weight="1">

      <fragment 
        class="com.myapp.blue.Fragments.ListFragment"
        android:id="@+id/frg_list"
        android:layout_weight="1"
        android:layout_width="0px"
        android:layout_height="match_parent" />
      <FrameLayout
        android:id="@+id/frg_detail"
        android:layout_weight="1"
        android:layout_width="0px"
        android:layout_height="match_parent" />
    </LinearLayout>
</LinearLayout>

Upvotes: 2

Hemanth S
Hemanth S

Reputation: 688

Mention width property in dp like 200dp

Upvotes: 0

Related Questions