简体   繁体   English

在底部导航视图中添加应用程序版本未正确显示

[英]add version of app at bottom navigation view is not displayed properly

As a lot of people are probably trying to do it, I am trying to add a footer to a navigation view.由于很多人可能正在尝试这样做,因此我正在尝试向导航视图添加页脚。 I did this:我这样做了:

<com.google.android.material.navigation.NavigationView
            android:id="@+id/navigationView"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_gravity="start"
            android:background="@color/background"
            android:clipToPadding="true"
            app:headerLayout="@layout/layout_nav_header"
            app:menu="@menu/navigation_menu">

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_gravity="bottom"
                android:layout_marginBottom="24dp"
                android:orientation="horizontal">

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginStart="20dp"
                    android:gravity="left"
                    android:text="@string/appVersion"/>

                <TextView
                    android:id="@+id/buildInfoTv"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"/>

            </LinearLayout>

        </com.google.android.material.navigation.NavigationView>

This working fine but not in 2 cases: small screen because the linearlayout overlap the menu and also if the keyboard is popped up, it move the layout.这工作正常但不是在两种情况下:小屏幕,因为线性布局与菜单重叠,如果键盘弹出,它会移动布局。

Any idea how to make sure that the linear layout with the app version stick to the bottom of the navigation or also below the menu item so it's not overlapping on small screen.知道如何确保应用程序版本的线性布局粘在导航底部或菜单项下方,这样它就不会在小屏幕上重叠。

Thanks谢谢

Try this once Note change widget values and parameters as per your requirements.尝试一次注意根据您的要求更改小部件值和参数。

OPTION 1-选项1-

<?xml version="1.0" encoding="utf-8"?>
<androidx.core.widget.NestedScrollView 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">

    <androidx.constraintlayout.widget.ConstraintLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

        <com.google.android.material.navigation.NavigationView
            android:id="@+id/navigationView"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:headerLayout="@layout/content_main"
            app:layout_constraintBottom_toTopOf="@+id/linearLayout"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent"
            app:menu="@menu/menu_main" />

        <LinearLayout
            android:id="@+id/linearLayout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginBottom="25dp"
            android:orientation="horizontal"
            android:padding="10dp"
            android:weightSum="1"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent">

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_weight="0.5"
                android:gravity="start|center"
                android:text="@string/app_name" />

            <TextView
                android:id="@+id/buildInfoTv"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_weight="0.5"
                android:gravity="start|center"
                android:text="@string/app_name" />

        </LinearLayout>

    </androidx.constraintlayout.widget.ConstraintLayout>
</androidx.core.widget.NestedScrollView> 

OPTION 2-选项 2-

<?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"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <androidx.core.widget.NestedScrollView
        android:layout_width="match_parent"
        android:layout_height="0dp"
        app:layout_constraintBottom_toTopOf="@+id/linear"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent">

        <com.google.android.material.navigation.NavigationView
            android:id="@+id/navigationView"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:headerLayout="@layout/content_main"

            app:menu="@menu/menu_main" />
    </androidx.core.widget.NestedScrollView>

    <LinearLayout
        android:id="@+id/linear"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="25dp"
        android:orientation="horizontal"
        android:padding="10dp"
        android:weightSum="1"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent">


        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="0.5"
            android:gravity="start|center"
            android:text="@string/app_name" />

        <TextView
            android:id="@+id/buildInfoTv"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="0.5"
            android:gravity="start|center"
            android:text="@string/app_name" />

    </LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM