Android:Intellij 按钮导航模板创建未使用的空间,隐藏其下的节点

     2023-04-18     289

关键词:

【中文标题】Android:Intellij 按钮导航模板创建未使用的空间,隐藏其下的节点【英文标题】:Android: Intellij Buttom nav template creates unused space, hides nodes under it 【发布时间】:2021-10-18 09:37:40 【问题描述】:

我在 Intellij 中使用按钮导航模板创建了一个 Android 项目。 我不能在顶部使用某个空间(见截图),它与按钮导航栏的大小相关,即使约束似乎是正确的。 它还隐藏/转换放置在它下面的元素,实际上还有一个 TextView 和一个微调器。

<?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"
        xmlns:tools="http://schemas.android.com/tools" android:id="@+id/container"
        android:layout_
        android:layout_
        android:paddingTop="?attr/actionBarSize">

    <com.google.android.material.bottomnavigation.BottomNavigationView
            android:id="@+id/nav_view"
            android:layout_
            android:layout_
            android:layout_marginStart="0dp"
            android:layout_marginEnd="0dp"
            android:background="?android:attr/windowBackground"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintLeft_toLeftOf="parent"
            app:layout_constraintRight_toRightOf="parent"
            app:menu="@menu/bottom_nav_menu"/>

    <fragment
            android:id="@+id/nav_host_fragment_activity_main"
            android:name="androidx.navigation.fragment.NavHostFragment"
            android:layout_
            android:layout_
            app:defaultNavHost="true"
            app:navGraph="@navigation/mobile_navigation"
            android:scrollbars="vertical" app:layout_constraintTop_toTopOf="parent"
            app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintBottom_toTopOf="@+id/nav_view" android:layout_marginBottom="40dp"
            android:paddingBottom="40dp"/>

</androidx.constraintlayout.widget.ConstraintLayout>

【问题讨论】:

【参考方案1】:

您必须将片段高度从wrap_content 删除到0dpmatch_constraint (match_parent)

match_constraint or 0dp :视图尽可能扩展以满足每一侧的约束(在考虑到视图的边距之后)。

Chain:链是一组通过双向位置约束相互链接的视图。链中的视图可以垂直或水平分布。对于您的情况,我们需要垂直链。见video

最后我从你那里删除android:paddingTop="?attr/actionBarSize" ConstraintLayout

试试下面的代码:

<?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"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/container"
android:layout_
android:layout_>


<fragment
    android:id="@+id/nav_host_fragment_activity_main"
    android:layout_
    android:layout_
    android:scrollbars="vertical"
    app:defaultNavHost="true"
    android:name="androidx.navigation.fragment.NavHostFragment"
    app:layout_constraintBottom_toTopOf="@+id/nav_view"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintHorizontal_bias="0.5"
    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_
    android:layout_
    android:background="?android:attr/windowBackground"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/nav_host_fragment_activity_main"
    app:menu="@menu/bottom_nav_menu"/>

</androidx.constraintlayout.widget.ConstraintLayout>

【讨论】:

Oweee 这个答案有效!您能否解释一下您做了什么以及我的缺陷是什么,以便我可以将您的答案标记为正确? @pikkuez 你只需要使用 0dp (match_constraint like match_parent ) 作为片段高度。我将垂直链分配给fragmentBottomNavigation 就是这样。请查看更新后的答案并附上解释。【参考方案2】:

删除

android:paddingTop="?attr/actionBarSize"

来自您的根 ConstraintLayout。

【讨论】:

java示例代码_在Intellij中,如何创建为测试添加导入语句的活动模板

java示例代码_在Intellij中,如何创建为测试添加导入语句的活动模板 查看详情

如何在 Android Studio / JetBrains IntelliJ IDEA 中编辑模板?

】如何在AndroidStudio/JetBrainsIntelliJIDEA中编辑模板?【英文标题】:HowtoedittemplateinAndroidStudio/JetBrainsIntelliJIDEA?【发布时间】:2016-08-2116:50:52【问题描述】:我想在AndroidStudio编辑器中添加更改的“loge”模板以删除最后一个必需的参... 查看详情

android导航组件向上按钮,箭头显示但popTo不起作用

】android导航组件向上按钮,箭头显示但popTo不起作用【英文标题】:androidnavigationcomponentupbutton,arrowdisplaysbutpopTonotworking【发布时间】:2019-10-0505:17:20【问题描述】:我正在使用jetpack导航组件,设置非常简单,一个活动(MainActivit... 查看详情

使用后退按钮在选项卡之间导航

...试创建我的第一个Xamarin移动应用程序,在使用返回按钮(android)导航回上一个屏幕/选项卡时我有点困惑。我创建了一个测试项目,并使用Xamarin表单shell来定义层次结构。我使用的导航类型是Tab。在我的测试应用程序中,我有2个标... 查看详情

在导航栏上创建标题和按钮

】在导航栏上创建标题和按钮【英文标题】:Createatitleandbuttononnavigationbar【发布时间】:2012-08-3109:42:20【问题描述】:我正在尝试复制iPhone的联系人应用程序并在导航栏上创建一个按钮。实际上视图不是UINavigation控制器。我刚刚... 查看详情

如何使用工具栏按钮创建导航

】如何使用工具栏按钮创建导航【英文标题】:HowtocreateNavigationusingToolBarbutton【发布时间】:2013-03-1212:13:09【问题描述】:我已经创建了一个工具栏按钮并给出了action()来导航到其他ViewController。但是代码不适用于Navigation。并且... 查看详情

Android如何使用工具栏中的按钮切换以使用片段打开/关闭导航抽屉

】Android如何使用工具栏中的按钮切换以使用片段打开/关闭导航抽屉【英文标题】:Androidhowtogglewiththebuttonintoolbartoopen/closenavigationdrawerwithFragments【发布时间】:2015-07-0307:42:33【问题描述】:在阅读了这么多教程和文档并花了一些... 查看详情

有没有办法使用 intellij 代码/文件模板生成多个文件/类? [复制]

】有没有办法使用intellij代码/文件模板生成多个文件/类?[复制]【英文标题】:Isthereawaytogeneratemultiplefiles/classeswithintellijcode/filetemplates?[duplicate]【发布时间】:2013-08-1004:09:43【问题描述】:我喜欢intellij的代码/文件模板,它们对... 查看详情

后退按钮关闭应用程序而不是转到上一个片段 android 导航组件

】后退按钮关闭应用程序而不是转到上一个片段android导航组件【英文标题】:Backbuttonclosesappinsteadofgoingtopreviousfragmentandroidnavigationcomponent【发布时间】:2020-03-2311:52:45【问题描述】:在创建一个非常简单的示例应用程序时,我无... 查看详情

[rk3568android11]开发之系统动态隐藏导航栏

目录前言一、创建全局变量二、设置应用添加隐藏导航栏按钮三、添加按钮功能 查看详情

如何使用左侧的后退按钮创建导航栏?

】如何使用左侧的后退按钮创建导航栏?【英文标题】:HowtocreateNavigationbarwithbackbuttontotheleft?【发布时间】:2013-03-0211:27:07【问题描述】:在我的应用程序中,我尝试使用导航栏后退按钮从第二个ViewController导航到第一个ViewContro... 查看详情

如何在导航控制器底部创建一个持久按钮?

】如何在导航控制器底部创建一个持久按钮?【英文标题】:HowdoIcreateapersistentbuttononthebottomofanavigationcontroller?【发布时间】:2016-10-1316:34:21【问题描述】:我有一个基于主/细节的iPhone应用程序。在不使用选项卡式导航样式应用... 查看详情

ug刀轨设置方法method这些有啥用

...出对话框,取消选中【只读】复选框,然后单击【确定】按钮。3.更改文件名(如:1.prt),不改变后缀。4.打开UG软件。打开1.prt文件。5进入加工模块,在操作导航器的空白处单击鼠标右键,在弹出的快捷菜单中选择【机床刀具视... 查看详情

Android - 将 ActionBar 后退按钮切换为导航按钮

】Android-将ActionBar后退按钮切换为导航按钮【英文标题】:Android-SwitchActionBarBackButtontoNavigationButton【发布时间】:2016-08-0310:49:43【问题描述】:我遇到以下问题:我知道如何设置工具栏以显示后退按钮图标而不是汉堡按钮图标。... 查看详情

创建新的基于导航的 iphone 应用程序时,如何在导航栏中添加按钮?

...建新的基于导航的iphone应用程序时,如何在导航栏中添加按钮?【英文标题】:Whencreatinganewnav-basediphoneapp,howdoyouaddabuttontothenavbar?【发布时间】:2011-04-0505:48:26【问题描述】:在创建新的基于导航的iphone应用时,如何向导航栏添... 查看详情

Android 物理/电容式导航按钮

】Android物理/电容式导航按钮【英文标题】:AndroidPhysical/CapacitiveNavigationButtons【发布时间】:2016-04-2819:25:15【问题描述】:如何检查设备上的屏幕或物理/电容式导航按钮【问题讨论】:【参考方案1】:你可以使用ViewConfiguration.g... 查看详情

Android - 从模板添加侧导航器

】Android-从模板添加侧导航器【英文标题】:Android-Addingsidenavigatorfromtemplate【发布时间】:2015-09-3009:19:28【问题描述】:我有一个现有的应用程序,我想在其中添加一个侧边导航器。我意识到AndroidSDK为此提供了一个模板(通过从... 查看详情

当用户按下后退按钮时隐藏导航抽屉

...创建了一个抽屉式导航。目前,一切正常,除了用户使用Android在屏幕底部提供的本机后退按钮(以及主页和最近使用的应用程序按钮)。如果用户使用本机返回按钮向后导航,导航抽屉仍将打开。如果用户使用A 查看详情