2012-07-10 73 views
0

我对Android非常陌生。我有一个非常简单的布局尚不工作:在活动中显示片段下方的按钮

<LinearLayout android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      xmlns:android="http://schemas.android.com/apk/res/android" 
      android:id="@+id/relativeLayout"> 
    <fragment android:layout_width="fill_parent" 
      android:layout_height="match_parent" 
      android:name="pl.nscr.playwatch.MainActivity$WatchListFragment" 
      android:id="@+id/watchlist"/> 
    <Button android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:text="Start service"/> 
</LinearLayout> 

现在我的问题是,该片段跨越一个活动的整体可用高度。我希望能够看到它下面的那个按钮,但我实际上不知道如何布置这个东西。

我尝试过使用RelativeLayout,但我最终显示了丑陋的片段上方的按钮。我究竟做错了什么?

更新

显然,这是一个愚蠢的错误。我再次改回RelativeLayout,但布局现在将宽度和高度设置为“fill_parent”,并且所有内容都按预期工作。

<RelativeLayout android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      xmlns:android="http://schemas.android.com/apk/res/android" 
      android:id="@+id/relativeLayout"> 
    <fragment android:layout_width="fill_parent" 
      android:layout_height="match_parent" 
      android:name="pl.nscr.playwatch.MainActivity$WatchListFragment" 
      android:id="@+id/watchlist" 
      android:layout_above="@+id/btnStartService"/> 
    <Button android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_alignParentBottom="true" 
      android:id="@id/btnStartService" 
      android:text="Start service"/> 
</RelativeLayout> 

回答

0

添加android:orientation="vertical"到的LinearLayout ..

2

请执行下列操作

  1. 添加机器人:方向= “垂直” 属性<LinearLayout>
  2. 添加layout_weight = “1” 属性<fragment />