2012-04-07 46 views
0

我使用两个带有片段的布局,一个用于portait模式,另一个用于横向。我需要为这两个布局添加一个粘性页脚,并且我已经成功将其添加到肖像布局,但是当我使用类似的代码进行布局时,它不起作用。如果设置了所述片段的layout_width0dp,我看到既不片段,如果我设置layout_widthwrap_contentfill_parent,片段彼此重叠。添加页脚到两个片段的布局

这是我到目前为止有:

<?xml version="1.0" encoding="utf-8"?> 

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="horizontal" 
    android:layout_height="fill_parent" 
    android:layout_width="fill_parent" 
> 
    <!-- Footer -->  
    <TextView 
      android:id="@+id/footer" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_alignParentBottom="true" 
    /> 
    <!-- Footer --> 

    <fragment android:name="com.app.listing1" 
      android:id="@+id/fragment1" 
      android:layout_width="wrap_content" 
      android:layout_height="fill_parent" 
      android:layout_above="@id/footer"    
    /> 

    <fragment android:name="com.app.listing2" 
      android:id="@+id/fragment2" 
      android:layout_width="wrap_content" 
      android:layout_height="fill_parent" 
      android:layout_above="@id/footer"    
    /> 

</RelativeLayout> 

编辑

我已经变得有点接近我想要的东西。如果我在fragment1上放置一个宽度,那么我就会得到我正在寻找的东西,但显然,这并不理想。出于某种原因,在两个片段的布局,以及每个片段内的布局设置layout_width =“WRAP_CONTENT”,结果在所述第一片段接管整个屏幕:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="horizontal" 
    android:layout_height="fill_parent" 
    android:layout_width="fill_parent" 
> 
    <!-- Footer -->  
    <TextView 
      android:id="@+id/footer" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_alignParentBottom="true" 
    /> 
    <!-- Footer --> 

    <fragment android:name="com.app.listing1" 
      android:id="@+id/fragment1" 
      android:layout_width="200dp" 
      android:layout_height="fill_parent" 
      android:layout_above="@id/footer"    
      android:layout_toLeftOf="@id/fragment2" 
    /> 

    <fragment android:name="com.app.listing2" 
      android:id="@+id/fragment2" 
      android:layout_width="wrap_content" 
      android:layout_height="fill_parent" 
      android:layout_above="@id/footer"    
      android:layout_toRightOf="@id/fragment1" 
    /> 

</RelativeLayout> 

回答

0

编辑:

这些片段相互重叠,因为您没有将它们对齐到您的RelativeLayout中。如果你希望他们被安排水平所以使用layout_toRightOflayout_toLeftOf

+0

嗯,没有工作。我添加机器人:layout_alignParentLeft =“真”的第一片段和机器人:layout_alignParentRight =“真”,以第二,但他们仍然重叠 – 2012-04-07 20:22:37

+1

对不起,我的意思left_of/right_of。如果你想布置你fragment2到片段1的右侧添加'机器人:layout_toRightOf =“@ ID /片段1”'你fragment2和你的片段1设置为'机器人:layout_width =“WRAP_CONTENT”' – 207 2012-04-07 20:28:55

+0

哎,仍然没有工作。现在它只在整个屏幕上显示片段1。你知道片段中的内容是否会影响它?我将RelativeLayouts的layout_width和layout_height设置为每个片段内的fill_parent。在处理Android布局时,我有这样的心理障碍。 – 2012-04-08 00:21:39