导航视图标题中的约束布局不采用全宽



这是我的NavigationView

<com.google.android.material.navigation.NavigationView
android:id="@+id/navView"
android:layout_width="500dp"
android:layout_height="match_parent"
android:layout_gravity="start"
app:headerLayout="@layout/nav_header_test"
android:theme="@style/NavigationViewStyleLand"
app:itemTextColor="@color/mainGray"
app:menu="@menu/navdrawer_menu">

这是我的HeaderLayout

<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/navHeader"
android:layout_width="match_parent"
android:layout_height="120dp"
android:background="@color/colorPrimary">
...
</androidx.constraintlayout.widget.ConstraintLayout>

ConstraintLayoutandroid:layout_width="match_parent"不工作。标头宽度小于NavigationView

当我尝试将ConstraintLayout替换为LinearLayout时,width是正确的。

有人能帮我理解为什么ConstraintLayout在这种情况下不合适吗?

我确实不知道,但你可以尝试一下,将宽度更改为0dp,并在xml中添加这一行,然后尝试

android:layout_width="0dp"
app:layout_constraintWidth_percent="1"

最新更新