Xml 如何在Android Studio中将工具栏和导航视图与表格布局合并在一起?
长话短说。我正在尝试在Android Studio中开发一个应用程序,它有一个从左侧滑动的导航视图,然后是一个包含三个选项卡的表格布局,分别是Medidas、Registros和Graficos。问题是,添加navigationView后,我再也看不到三个选项卡中的文本了 我不是布局专家,因此在排列xml标记时遇到问题。请参阅下面的代码:Xml 如何在Android Studio中将工具栏和导航视图与表格布局合并在一起?,xml,android-studio,android-layout,layout,view,Xml,Android Studio,Android Layout,Layout,View,长话短说。我正在尝试在Android Studio中开发一个应用程序,它有一个从左侧滑动的导航视图,然后是一个包含三个选项卡的表格布局,分别是Medidas、Registros和Graficos。问题是,添加navigationView后,我再也看不到三个选项卡中的文本了 我不是布局专家,因此在排列xml标记时遇到问题。请参阅下面的代码: <?xml version="1.0" encoding="utf-8"?> <androidx.drawerlayout.widget.D
<?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:layout_width="match_parent"
android:id="@+id/drawer_layout"
android:fitsSystemWindows="true"
android:layout_height="match_parent"
tools:context=".PantallaDatos"
tools:openDrawer="start">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="@color/colorPrimary"
android:elevation="4dp"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />
<View
android:layout_width="match_parent"
android:layout_height="3dp"
android:background="@color/colorDivider"
app:layout_constraintBottom_toBottomOf="@id/tabLayout" />
<com.google.android.material.tabs.TabLayout
android:id="@+id/tabLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:color/transparent"
app:layout_constraintTop_toTopOf="parent"
app:tabIndicatorHeight="3dp"
app:tabMode="fixed"
app:tabPaddingBottom="8dp"
app:tabPaddingTop="15dp" />
<androidx.viewpager2.widget.ViewPager2
android:id="@+id/viewPager"
android:layout_width="match_parent"
android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toBottomOf="@id/tabLayout" />
</LinearLayout>
<com.google.android.material.navigation.NavigationView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:id="@+id/nav_view"
app:headerLayout="@layout/nav_header"
app:menu="@menu/drawer_menu"/>
正如您在蓝图中看到的,我有许多标签相互叠加。我认为这是导致我无法正确查看选项卡布局的原因。有人能帮我整理一下标签吗?或者也许有更好的方法来做这一切
先谢谢你
<?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:layout_width="match_parent"
android:id="@+id/drawer_layout"
android:fitsSystemWindows="true"
android:layout_height="match_parent"
tools:context=".PantallaDatos"
tools:openDrawer="start">
<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">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="@color/colorPrimary"
android:elevation="4dp"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />
<View
android:layout_width="match_parent"
android:layout_height="3dp"
android:background="@android:color/background_dark"
app:layout_constraintBottom_toBottomOf="@id/tabLayout" />
<com.google.android.material.tabs.TabLayout
android:id="@+id/tabLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:color/transparent"
app:layout_constraintTop_toTopOf="parent"
app:tabIndicatorHeight="3dp"
app:tabMode="fixed"
app:tabPaddingBottom="8dp"
app:tabPaddingTop="15dp" />
<androidx.viewpager2.widget.ViewPager2
android:id="@+id/viewPager"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_constraintTop_toBottomOf="@id/tabLayout" />
</LinearLayout>
<com.google.android.material.navigation.NavigationView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:id="@+id/nav_view"
app:headerLayout="@layout/nav_header"
app:menu="@menu/drawer_menu"/>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
</androidx.drawerlayout.widget.DrawerLayout>