[英]Android: Intellij Buttom nav template creates unused space, hides nodes under it
I created an Android project in Intellij with the buttom nav template.我使用按钮导航模板在 Intellij 中创建了一个 Android 项目。 I can not use a certain space on the top (see screenshot) which corelates in size with the buttom nav bar, even though the constrains seem to be right.
我不能在顶部使用某个空间(见屏幕截图),它的大小与按钮导航栏相关,即使约束似乎是正确的。 As well it hides/converes elements which are placed under it, actually there is a TextView and a spinner.
它还隐藏/隐藏放置在其下方的元素,实际上有一个 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_width="match_parent"
android:layout_height="match_parent"
android:paddingTop="?attr/actionBarSize">
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="@+id/nav_view"
android:layout_width="0dp"
android:layout_height="wrap_content"
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_width="match_parent"
android:layout_height="wrap_content"
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>
You have to remove the fragment height from wrap_content
to 0dp
ie match_constraint
( match_parent
)您必须将片段高度从
wrap_content
删除到0dp
即match_constraint
( match_parent
)
match_constraint or 0dp : The view expands as much as possible to meet the constraints on each side (after accounting for the view's margins). match_constraint 或 0dp :视图尽可能扩展以满足每一侧的约束(在考虑视图的边距之后)。
Chain : A chain is a group of views that are linked to each other with bi-directional position constraints. 链:链是一组通过双向 position 约束相互链接的视图。 The views within a chain can be distributed either vertically or horizontally.
链中的视图可以垂直或水平分布。 For your case we need a Vertical Chain.
对于您的情况,我们需要垂直链。 See video
看视频
And last I remove the android:paddingTop="?attr/actionBarSize"
from you ConstraintLayout
最后我从你的
ConstraintLayout
中删除了android:paddingTop="?attr/actionBarSize"
Try the below code:试试下面的代码:
<?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_width="match_parent"
android:layout_height="match_parent">
<fragment
android:id="@+id/nav_host_fragment_activity_main"
android:layout_width="match_parent"
android:layout_height="0dp"
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_width="0dp"
android:layout_height="wrap_content"
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>
Remove消除
android:paddingTop="?attr/actionBarSize"
from your root ConstraintLayout.从你的根 ConstraintLayout。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.