首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >TabLayout高度

TabLayout高度
EN

Stack Overflow用户
提问于 2020-02-22 15:17:34
回答 1查看 41关注 0票数 0

我需要帮助。这个解决方案一定很愚蠢,但我已经3个小时没能解出来了。我有一个工具栏和一个TabLayout,它们工作得很好。我唯一的问题是它所需要的TabLayout的高度是工具栏的高度。然后我得到了短TabLayout的大小。

我留下了所有的XML:

activity_main.xml

代码语言:javascript
运行
复制
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
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:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">

<include
layout="@layout/activity_drawer" />

<com.google.android.material.tabs.TabLayout
android:id="@+id/tabs"
android:layout_width="match_parent"
android:layout_height="72dp"
android:backgroundTint="@color/white"
android:minHeight="72dp"
app:tabIconTint="@color/white"
app:tabIndicatorColor="@color/colorAccent"
app:tabIndicatorHeight="3dp"
app:tabSelectedTextColor="@color/colorAccent"
app:tabTextColor="@color/white">

</com.google.android.material.tabs.TabLayout>

</RelativeLayout>

Activity_drawer.xml

代码语言:javascript
运行
复制
<?xml version="1.0" encoding="utf-8"?>
<androidx.drawerlayout.widget.DrawerLayout 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/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:openDrawer="start"
tools:showIn="@layout/activity_main">


<include
 layout="@layout/app_bar_drawer"
 android:layout_width="match_parent"
 android:layout_height="match_parent" />

<com.google.android.material.navigation.NavigationView
android:id="@+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true"
app:headerLayout="@layout/nav_header_drawer"
app:menu="@menu/activity_drawer_drawer" />


</androidx.drawerlayout.widget.DrawerLayout>

app_bar_drawer.xml

代码语言:javascript
运行
复制
<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.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:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">


<com.google.android.material.appbar.AppBarLayout
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay">


<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/AppTheme.PopupOverlay">

</androidx.appcompat.widget.Toolbar>

</com.google.android.material.appbar.AppBarLayout>



<include layout="@layout/content_drawer" />

</androidx.coordinatorlayout.widget.CoordinatorLayout>

content_drawer.xml

代码语言:javascript
运行
复制
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 
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:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:showIn="@layout/app_bar_drawer">

<fragment
    android:id="@+id/nav_host_fragment"
    android:name="androidx.navigation.fragment.NavHostFragment"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:defaultNavHost="true"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRightOf="parent"
    app:layout_constraintTop_toTopOf="parent"
    app:navGraph="@navigation/mobile_navigation" />

<androidx.viewpager.widget.ViewPager
    android:id="@+id/viewPager"
    android:layout_width="wrap_content"
    android:layout_height="0dp"
    android:layout_above="@id/nav_host_fragment"
    app:layout_constraintBottom_toBottomOf="@+id/nav_host_fragment"
    app:layout_constraintEnd_toEndOf="@id/nav_host_fragment"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>

EN

回答 1

Stack Overflow用户

发布于 2020-02-22 16:44:26

您使用的是Relativelayout,因此您必须使用

代码语言:javascript
运行
复制
 android:layout_below  

属性,它将以线性方式排列所有内容。或者你可以使用线性布局与方向垂直作为根布局,这将自动安排所有布局线性和垂直...希望这能对你有所帮助..

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/60349920

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档