Как сделать так, чтобы нижняя навигация оставалась в нижней части LinearLayout? - PullRequest
0 голосов
/ 05 октября 2019

Как сделать так, чтобы нижняя навигация оставалась в нижней части страницы с помощью LinearLayout? Большинство решений, которые я нашел, это то, что они использовали RelativeLayout вместо LinearLayout.

Ниже приведен мой код

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/white">

    <androidx.appcompat.widget.Toolbar

        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/purpleBoo"
        android:minHeight="?attr/actionBarSize"
        android:theme="@style/ThemeOverlay.AppCompat.Dark">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:text=" MY ACCOUNT"
            android:textStyle="bold"
            android:textColor="@color/white">

        </TextView>
    </androidx.appcompat.widget.Toolbar>


    <com.google.android.material.bottomnavigation.BottomNavigationView
        android:id="@+id/btm_nav"
        app:itemIconTint="@color/bottom_nav_color"
        app:itemTextColor="@color/bottom_nav_color"
        app:menu="@menu/bottom_nav"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/purpleBoo"
        android:clipToPadding="false" />

</LinearLayout>


1 Ответ

0 голосов
/ 05 октября 2019

Это довольно просто - ваш xml должен выглядеть так:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/white">

    <androidx.appcompat.widget.Toolbar

        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/purpleBoo"
        android:minHeight="?attr/actionBarSize"
        android:theme="@style/ThemeOverlay.AppCompat.Dark">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:text=" MY ACCOUNT"
            android:textStyle="bold"
            android:textColor="@color/white">

        </TextView>
    </androidx.appcompat.widget.Toolbar>
    <!--Just add in between the action bar and bottom bar some other view with height = 0dp and weight = 1. I added one more LinearLayout-->
    <LinearLayout
        android:id="@+id/content"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:orientation="vertical">

    </LinearLayout>

    <com.google.android.material.bottomnavigation.BottomNavigationView
        android:id="@+id/btm_nav"
        app:itemIconTint="@color/bottom_nav_color"
        app:itemTextColor="@color/bottom_nav_color"
        app:menu="@menu/bottom_nav"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/purpleBoo"
        android:clipToPadding="false" />

</LinearLayout>

В других случаях это не будет работать. В LinearLayout должен быть хотя бы один weight, но не height вид.

Надеюсь, это поможет.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...