Фрагмент / Панель инструментов из фрагмента показана в неправильном положении - PullRequest
0 голосов
/ 21 сентября 2019

Я начал использовать панель инструментов вместо ActionBar.Панель инструментов устанавливается в каждом макете.Но, как вы можете видеть на рисунке, фрагмент с панелью инструментов не начинается прямо под строкой состояния.Кроме того, панель инструментов падает с текстом из макета сетки.

enter image description here

Вот код активности_основной_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"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:tools="http://schemas.android.com/tools">

    <androidx.constraintlayout.widget.ConstraintLayout
        android:id="@+id/container"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:paddingTop="?attr/actionBarSize">

        <fragment
            android:id="@+id/nav_host_fragment"
            android:name="androidx.navigation.fragment.NavHostFragment"
            android:layout_width="0dp"
            android:layout_height="0dp"
            app:defaultNavHost="true"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent"
            app:navGraph="@navigation/mobile_navigation" />

        <com.google.android.material.bottomnavigation.BottomNavigationView
            android:id="@+id/nav_view"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:background="?android:attr/windowBackground"
            app:elevation="0.1dp"
            app:itemIconTint="@drawable/nav_item_colors"
            app:layout_constraintBottom_toBottomOf="@+id/nav_host_fragment"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:menu="@menu/bottom_nav_menu" />

    </androidx.constraintlayout.widget.ConstraintLayout>

</androidx.coordinatorlayout.widget.CoordinatorLayout>

Здесьэто код фрагмента_finder.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"
    android:layout_width="match_parent"
    xmlns:tools="http://schemas.android.com/tools"
    android:backgroundTint="#ffffff"
    android:layout_height="match_parent">

    <com.google.android.material.appbar.AppBarLayout
        android:id="@+id/appbar"
        android:layout_height="wrap_content"
        tools:targetApi="21"
        app:elevation="0dp"
        android:layout_width="match_parent">

        <androidx.appcompat.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            app:elevation="0dp"
            android:layout_height="match_parent">

            <TextView
                android:id="@+id/toolbar_title"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:text="Toolbar Title" />

        </androidx.appcompat.widget.Toolbar>

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

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        android:weightSum="7" >

        <GridLayout
            android:layout_gravity="center_horizontal|center_vertical"
            android:layout_width="wrap_content"
            android:layout_height="0dp"
            android:layout_weight="0.5"
            android:columnCount="3"
            android:rowCount="1"
            android:alignmentMode="alignMargins" >

            <TextView
            android:id="@+id/text_country"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginStart="0dp"
            android:layout_marginTop="0dp"
            android:layout_marginEnd="5dp"
            android:fontFamily="@font/pacifico"
            android:layout_gravity="left"
            android:textSize="20sp" />

            <TextView
                android:id="@+id/text_finder"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginStart="0dp"
                android:layout_marginTop="0dp"
                android:layout_marginEnd="5dp"
                android:fontFamily="@font/pacifico"
                android:textAlignment="center"
                android:textSize="20sp" />

            <TextView
                android:id="@+id/text_age"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginStart="0dp"
                android:layout_marginTop="0dp"
                android:layout_marginEnd="5dp"
                android:fontFamily="@font/pacifico"
                android:layout_gravity="right"
                android:textSize="20sp" />

        </GridLayout>

        <androidx.cardview.widget.CardView
            android:layout_width="match_parent"
            android:layout_weight="5"
            android:layout_height="0dp"
            app:cardCornerRadius="15dp"
            android:layout_margin="5dp"
            android:elevation="10dp" >

            <ImageView
                android:id="@+id/profileview"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:src="@drawable/ex1"
                android:scaleType="centerCrop" />

        </androidx.cardview.widget.CardView>

        <GridLayout
            android:layout_gravity="center_horizontal|center_vertical"
            android:layout_width="wrap_content"
            android:layout_height="0dp"
            android:layout_weight="1"
            android:columnCount="3"
            android:rowCount="1"
            android:alignmentMode="alignMargins" >

            <ImageView
                android:id="@+id/schlecht"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:src="@drawable/schlecht"
                android:scaleType="centerCrop" />

            <ImageView
                android:id="@+id/hot"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:src="@drawable/hot"
                android:scaleType="centerCrop" />

            <ImageView
                android:id="@+id/gut"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:src="@drawable/gut"
                android:scaleType="centerCrop" />

        </GridLayout>

    </LinearLayout>

    </RelativeLayout>

</androidx.coordinatorlayout.widget.CoordinatorLayout>

Я надеюсь, что кто-нибудь может мне помочь с этой проблемой.

С уважением, Джереми

1 Ответ

3 голосов
/ 21 сентября 2019

Ответ на первую часть: Удалить строку ниже из Activity_main

android:paddingTop="?attr/actionBarSize"

Добавить строку к Относительному расположению в frag_finder

android:paddingTop="?attr/actionBarSize"
...