java - BottomNavigationView 被放置在父级之上
问题描述
我使用 AndroidStudio 内置的 BottomNavigationView 并试图将它放在父级的底部。我正在使用 layout_gravity="bottom",但它仍然被移到顶部。关于我做错了什么的任何想法?
<?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:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<RelativeLayout
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_marginStart="10dp"
android:layout_marginTop="10dp">
<de.hdodenhof.circleimageview.CircleImageView
android:id="@+id/profile_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/profil"/>
</RelativeLayout>
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="@+id/bottom_navigation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:background="@android:color/holo_green_dark"
app:itemIconTint="@android:color/white"
app:itemTextColor="@android:color/white"
app:menu="@menu/bottom_menu" />
</LinearLayout>
解决方案
正如我在评论中所说,另一种方法是使用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"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<RelativeLayout
android:id="@+id/relativeLayout"
android:layout_width="40dp"
android:layout_height="0dp"
android:layout_marginStart="10dp"
android:layout_marginTop="10dp"
app:layout_constraintBottom_toTopOf="@+id/bottom_navigation"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<de.hdodenhof.circleimageview.CircleImageView
android:id="@+id/profile_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/profil" />
</RelativeLayout>
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="@+id/bottom_navigation"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:background="@android:color/holo_green_dark"
app:itemIconTint="@android:color/white"
app:itemTextColor="@android:color/white"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/relativeLayout"
app:menu="@menu/bottom_menu" />
</androidx.constraintlayout.widget.ConstraintLayout>
推荐阅读
- reactjs - 如何使用 react 和 redux 从不同/其他页面滚动到视图?
- node.js - 如何在nodejs中的选项中循环url
- javascript - 如何始终使用 selenium java 在日期选择器中从当前日期开始 21 天选择日期
- go - go get -u github.com/onsi/ginkgo/ginkgo 突然开始抛出错误
- ios - 弹出显示没有迅速覆盖整个屏幕
- google-sheets - Google Sheet 中的数组约束公式问题
- caching - 在 NestJS 中缓存 axios httpService
- delphi - 将非类函数添加到通用 TArray 类
- java - 无法在我的项目中创建唯一键约束
- python - 如何检查 tkinter 中 bind() 函数的状态?(Python 3.8)