操作栏选项卡片段布局仅覆盖屏幕的一部分

时间:2014-02-20 18:57:18

标签: android tabs android-actionbar

从Android示例中我可以看到该怎么做 ActionBar选项卡以及如何使用选项卡进行片段切换,但在示例中,片段布局覆盖整个屏幕。 我想在屏幕底部放置一些控件,  它应该是活动本身的一部分并受其控制。

所以我想在点击标签并在片段之间切换时保持屏幕底部相同。

谢谢

2 个答案:

答案 0 :(得分:1)

使用LinearLayouts将屏幕分成两部分。例如,给一个线性布局重量为9(占据屏幕的90%),另一个为1的重量(占屏幕的10%) - 然后将碎片放入LinearLayout中,重量为9.这样你的碎片就有了他们自己的容器,你底部有另一个容器,你的活动可以使用它来做任何喜欢的事情,它就像你的标签一样可以从所有片段中看到和访问。

答案 1 :(得分:0)

正如sunil所说,您必须在MainActivity中创建底部布局。所以布局将如下所示。

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <FrameLayout
     android:id="@+id/fragment_holder"
     android:layout_width="match_parent"
     android:layout_height="0dp"
     android:weight="9"/>

    <Button
     android:id="@+id/bottomButton"
     android:layout_width="match_parent"
     android:layout_height="0dp"
     android:weight="1"
     android:text="Common BUtton"/>
</LinearLayout>

在FragmentTransaction中传递R.id.fragment_holder,因为它将是片段的容器。