屏幕底部的Android TabLayout [英] Android TabLayout on the bottom of the screen

查看:57
本文介绍了屏幕底部的Android TabLayout的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

启动新的选项卡式活动时,我具有以下生成的XML代码:

I have this generated XML code when I started a new Tabbed Activity:

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/main_content"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    tools:context="eis1617.muellerkimmeyer.app.MainActivity">

    <android.support.design.widget.AppBarLayout
        android:id="@+id/appbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:paddingTop="@dimen/appbar_padding_top"
        android:theme="@style/AppTheme.AppBarOverlay">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="?attr/colorPrimary"
            app:layout_scrollFlags="scroll|enterAlways"
            app:popupTheme="@style/AppTheme.PopupOverlay">

        </android.support.v7.widget.Toolbar>

        <android.support.design.widget.TabLayout
            android:id="@+id/tabs"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"/>

    </android.support.design.widget.AppBarLayout>

    <android.support.v4.view.ViewPager
        android:id="@+id/container"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior" />

    <android.support.design.widget.FloatingActionButton
        android:id="@+id/fab"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="end|bottom"
        android:layout_margin="@dimen/fab_margin"
        app:srcCompat="@android:drawable/ic_dialog_email" />

</android.support.design.widget.CoordinatorLayout>

我该如何准确地更改它,以使标签栏位于屏幕底部?在TabLayout标记上,我已经尝试添加 android:layout_gravity ="bottom" ,但是它并没有改变任何内容.

How exactly must I change it, that the tab bar will be placed on the bottom of the screen? On the TabLayout Tag I already tried to add android:layout_gravity="bottom", but it didnt change anything.

推荐答案

这是我的实现方式:

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="in.mylo.pregnancy.baby.app.FAB">

<android.support.design.widget.AppBarLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <android.support.v7.widget.Toolbar
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="@android:color/white" />
</android.support.design.widget.AppBarLayout>

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

   <android.support.design.widget.AppBarLayout
       android:layout_width="match_parent"
       android:layout_height="wrap_content"
       android:layout_gravity="bottom"
       android:background="@android:color/white"
       android:elevation="80dp">

     <android.support.design.widget.TabLayout
          android:id="@+id/bottomNavigation"
          android:layout_width="match_parent"
          android:layout_height="56dp"
          android:clickable="true"
          app:tabBackground="?attr/selectableItemBackground"
          app:tabGravity="fill"
          app:tabIndicatorHeight="0dp"
          app:tabMode="fixed"
          app:tabSelectedTextColor="@android:color/black" />

   </android.support.design.widget.AppBarLayout>

</android.support.design.widget.CoordinatorLayout>

这篇关于屏幕底部的Android TabLayout的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆