这是我的
这是我的
这是我的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>
ConstraintLayout
的android:layout_width="match_parent"
不工作。标头宽度小于NavigationView
。
当我尝试将ConstraintLayout
替换为LinearLayout
时,width
是正确的。
有人能帮我理解为什么ConstraintLayout
在这种情况下不合适吗?
我确实不知道,但你可以尝试一下,将宽度更改为0dp,并在xml中添加这一行,然后尝试
android:layout_width="0dp"
app:layout_constraintWidth_percent="1"