【问题标题】:Android. TabWidget always on top for now?安卓。 TabWidget 现在总是在最前面?
【发布时间】:2012-12-17 05:15:18
【问题描述】:

我正在研究使用片段处理选项卡。我想知道如何将 TabWidget 放在页面底部。

我正在研究 FragmentTab.java 示例(支持库 v4)。

有一个 XML 布局:

<android.support.v4.app.FragmentTabHost
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/tabhost"
android:layout_width="match_parent"
android:layout_height="match_parent">

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

    <TabWidget
        android:id="@android:id/tabs"
        android:orientation="horizontal"
        android:layout_width="match_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="@+id/realtabcontent"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"/>

</LinearLayout>

无论我做什么 TabWidget 仍然是最重要的。实际上我可以完全删除 TabWidget 标签,但项目仍然会成功启动,并且 TabWidget 会再次出现在顶部。

这是否意味着现在使用 FragmentActivity 和 FragmentTabHost 我只能让我的 TabWidget 在顶部?

谢谢。

【问题讨论】:

  • 你有什么解决办法吗?

标签: android tabs fragment tabwidget android-fragmentactivity


【解决方案1】:

你快到了!我认为这里缺少的是您将TabWidget 之前 FrameLayout。此外,我认为您不能将 0dp 宽度和高度设置为您的@android:id/tabcontent,它需要可见并具有layout_weight="1"。试试这个(已编辑):

<android.support.v4.app.FragmentTabHost
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@android:id/tabhost"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

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

        <FrameLayout
            android:id="@android:id/tabcontent"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"/>
       <!--
        <FrameLayout
            android:id="@+id/realtabcontent"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1"/>
       -->
        <TabWidget
            android:id="@android:id/tabs"
            android:orientation="horizontal"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="0" />

    </LinearLayout>
</android.support.v4.app.FragmentTabHost>

【讨论】:

  • 是的,我试过这样做,但没有帮助。我什至完全删除了 TabWidget 标签,标签小部件仍然位于底部...
  • 那么问题出在我的想法...realtabcontent不可能是你可见的FrameLayout,tabcontent是需要这些属性的那个。查看更新。
  • 对不起,塞尔吉奥,但它再次没有帮助。可能是我的 sdk 要求这样做。我有 minSdkVersion="9" 和 targetSdkVersion="15"...
猜你喜欢
  • 1970-01-01
  • 2015-07-06
  • 2011-09-24
  • 2016-03-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多