我一直在研究一个由带有许多选项卡的 GUI 组成的小项目。我对片段的概念很陌生,但似乎它们是 android 选项卡环境中的最佳实践。我设法编写了一个简单的选项卡应用程序,可以在 3 个选项卡之间切换。
我遇到的唯一问题是当我尝试将选项卡放在屏幕底部时。当它们位于底部时,选项卡小部件覆盖容器(在这种情况下为框架布局),因此没有任何反应,单击各个选项卡时屏幕保持不变。
以下 XML 布局代表了良好的版本(选项卡位于屏幕顶部):
<?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">
<TabHost
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"
>
<TabWidget
android:id="@android:id/tabs"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="0"
/>
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_weight="0"/>
<FrameLayout
android:id="@+android:id/realtabcontent"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"/>
</LinearLayout>
</TabHost>
</LinearLayout>
以下XML布局表示不起作用的版本,当标签位于屏幕底部时:
<?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">
<TabHost
android:id="@android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<RelativeLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TabWidget
android:id="@android:id/tabs"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
/>
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="0dp"
android:layout_height="0dp"
/>
<FrameLayout
android:id="@+android:id/realtabcontent"
android:layout_width="fill_parent"
android:layout_height="0dp"
/>
</RelativeLayout>
</TabHost>
</LinearLayout>
我将布局更改为 relativelayout 并将此命令:android:layout_alignParentBottom="true" 添加到 tabwidget。有没有人对我如何解决这个问题有另一种想法?提前致谢。