TabLayout Height

问题描述 投票:-1回答:1

我需要帮助。解决方案必须是愚蠢的,但是我已经有3个小时无法解决了。我有一个工具栏,我有一个TabLayout,可以完美地工作。我唯一的问题是它占用的TabLayout的高度是工具栏的高度。然后,我得到了简短的TabLayout的大小。

我保留所有XML:

activity_main.xml

<?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

<?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

<?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

<?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>

IMAGEN

android android-studio android-tablayout
1个回答
0
投票

您正在使用Relativelayout,因此必须使用]安排所有属性>

 android:layout_below  

将线性排列的属性。要么您可以使用方向垂直的linearlayout作为根布局这将自动排列所有布局的线性和垂直...希望对您有帮助。.

© www.soinside.com 2019 - 2024. All rights reserved.