【发布时间】:2011-09-09 03:04:23
【问题描述】:
我的选项卡活动中有四个选项卡,并且无论当前选项卡选择如何,我都需要一个在选项卡活动顶部带有三个按钮的工具栏。
我可以为此使用viewstub吗?
谁能帮我实现这个目标?
【问题讨论】:
标签: android view android-activity
我的选项卡活动中有四个选项卡,并且无论当前选项卡选择如何,我都需要一个在选项卡活动顶部带有三个按钮的工具栏。
我可以为此使用viewstub吗?
谁能帮我实现这个目标?
【问题讨论】:
标签: android view android-activity
<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/tabhost"
android:layout_width="fill_parent" android:layout_height="fill_parent">
<LinearLayout android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content"
android:id="@+id/header">
<TextView android:layout_width="wrap_content" android:layout_height="wrap_content"
android:text="woopra" android:textColor="#ffffff" android:textSize="36sp"
android:textStyle="bold"/>
</LinearLayout>
<FrameLayout android:layout_width="fill_parent" android:layout_height="wrap_content">
<TabWidget android:id="@android:id/tabs" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:visibility="gone"/>
<LinearLayout android:layout_width="fill_parent" android:layout_height="64dip">
<Button android:layout_height="fill_parent" android:layout_width="0dip"
android:layout_weight="1.0" android:id="@+id/dashboard_tab"
android:onClick="tabHandler" android:text="Dashboard"/>
<Button android:layout_height="fill_parent" android:layout_width="0dip"
android:layout_weight="1.0" android:id="@+id/visitors_tab"
android:onClick="tabHandler" android:text="Vistors"/>
<Button android:layout_height="fill_parent" android:layout_width="0dip"
android:layout_weight="1.0" android:id="@+id/chat_tab" android:onClick="tabHandler"
android:text="Chat"/>
<Button android:layout_height="fill_parent" android:layout_width="0dip"
android:layout_weight="1.0" android:id="@+id/reports_tab"
android:onClick="tabHandler" android:text="Reports"/>
</LinearLayout>
</FrameLayout>
<FrameLayout android:id="@android:id/tabcontent" android:layout_width="fill_parent" android:layout_height="0dip"
android:layout_weight="1.0"/>
</LinearLayout>
这里的 id 为 'tabcontent' 的框架布局是我们选项卡的内容所在的位置。无论选择哪个选项卡,您在此框架布局之外放置的任何内容都将在选项卡活动中。
如果您查看 xml 的顶部,您会看到一个带有 id 'header' 的线性布局。这是我制作的标题布局,在选项卡布局中始终可见。您可以通过放置按钮而不是像我所做的那样放置文本视图来创建工具栏。
【讨论】:
把你的工具栏放到布局里,有什么问题?
【讨论】: