【问题标题】:Want to set Tabs in Bottom with the help of following code想借助以下代码在底部设置选项卡
【发布时间】:2016-09-14 08:11:04
【问题描述】:

在我的应用程序中,我设置了 Navigation DrawerTabs 以下代码适用于Tabs,我正在尝试将其固定在底部,但它根本不起作用。

ma​​in.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:orientation="vertical"
    android:layout_height="wrap_content">


    <android.support.design.widget.TabLayout
        android:id="@+id/tabs"
        app:tabGravity="fill"
        app:tabMode="fixed"
        android:background="@color/material_blue_grey_800"
        app:tabIndicatorColor="@color/orange"
        app:tabSelectedTextColor="@color/orange"
        app:tabTextColor="@color/white"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
    </android.support.design.widget.TabLayout>

    <android.support.v4.view.ViewPager
        android:id="@+id/viewpager"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

    </android.support.v4.view.ViewPager>



</LinearLayout>

我想在 bottom 中设置Tabs 谁能告诉我如何使用此代码在底部设置Tabs

【问题讨论】:

标签: android tabs fragment


【解决方案1】:

您需要更改 LinearLayout 中的顺序。 Viewpager 将向上,而 TabLayout 将向下。

viewpager 之后需要将 weight 属性赋予 1。

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:orientation="vertical"
    android:layout_height="wrap_content">

    <android.support.v4.view.ViewPager
        android:id="@+id/viewpager"
        android:layout_width="match_parent"
        android:layout_weight="1"
        android:layout_height="match_parent">
    </android.support.v4.view.ViewPager>

    <android.support.design.widget.TabLayout
        android:id="@+id/tabs"
        app:tabGravity="fill"
        app:tabMode="fixed"
        android:background="@color/material_blue_grey_800"
        app:tabIndicatorColor="@color/orange"
        app:tabSelectedTextColor="@color/orange"
        app:tabTextColor="@color/white"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
    </android.support.design.widget.TabLayout>
</LinearLayout>

【讨论】:

  • 我已经从上面的链接中得到了它......但现在我想设置一个图标而不是文本。那你能告诉我答案吗?
  • 我已经在这里给出了答案,stackoverflow.com/a/39488685/2900893
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2023-03-25
  • 1970-01-01
  • 2017-11-14
  • 2016-02-05
  • 1970-01-01
  • 1970-01-01
  • 2020-06-09
相关资源
最近更新 更多