Как объединить панель инструментов и NavigationView вместе с моим TabLayout в Android Studio? - PullRequest
0 голосов
/ 10 марта 2020

Итак, короче говоря. Я пытаюсь создать приложение в Android Studio, имеющее навигационное представление, которое скользит слева, а затем TabLayout с тремя вкладками в нем (Medidas, Registros y Graficos). Проблема заключается в том, что после добавления навигации, я не могу больше видеть текст на трех вкладках.

Я не являюсь экспертом по макету, поэтому у меня проблемы с размещением тегов 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: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"/>

enter image description here

Как вы можете видеть на чертеже, у меня есть много тегов, наложенных один в еще один. Я думаю, что это заставляет меня не видеть макет вкладки правильно. Может ли кто-нибудь помочь мне с тегами? или, может быть, есть лучший способ сделать все это.

Заранее спасибо

1 Ответ

1 голос
/ 10 марта 2020
<?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>
...