1

我已经使用碎片创建了一个应用程序来显示左侧的列表和右侧的详细信息。Android碎片不会显示在大布局上

以下是我在布局大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> 

布局,这是Appointments.xaml从布局文件夹

<?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> 

这里是我的活动代码

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); 
    } 
} 

该应用程序在手机上完美运行,但是当我使用平板电脑运行此应用程序没有我的f ragments秀。我按照这个Xamarin walkthrough上的指示,并看到其他的stackoverflow帖子,他们说宽度应该是0px或dp。但是我无法将列表片段显示在我的平板电脑上。我在这里错过了什么?在dp

+0

你的大布局具有在水平工具栏'''LinearLayout' 。如果该工具栏是“LinearLayout”的全部宽度,那么''和''将被推出'LinearLayout'的一侧。 –

+0

那么我怎样才能把我的工具栏放在上面呢,我应该在垂直线性布局中使用水平线性吗? – progrAmmar

+0

当然,这会工作。这就是我所要做的,无论如何,因为LinearLayout提供的权重似乎是您所依赖的。你也许可以用'PercentRelativeLayout'来做同样的事情,但我不确定。我没有用过。 –

回答

2

的问题是,您包括工具栏最可能有layout_width=match_parent,因此占据与水平方向的整个线性布局。如果你希望你的工具栏在顶部,只是让你的线性布局垂直,并与你的片段中插入另一条水平直线布局:

<?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> 
0

提及width属性一样200dp