NavigationView 标头中的 ConstraintLayout 不采用全宽
这是我的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>
android:layout_width="match_parent"
for ConstraintLayout
不起作用。标题宽度小于 NavigationView
。
当我尝试将 ConstraintLayout
替换为 LinearLayout
时,width
是正确的。
有人可以帮助我理解为什么 ConstraintLayout
在这种情况下不正确吗?
Here is my 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">
Here is my 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>
android:layout_width="match_parent"
for ConstraintLayout
not working. Header width is less then NavigationView
.
When I'm trying to replace ConstraintLayout
to LinearLayout
, width
is correct.
Can somebody help me understand why does ConstraintLayout
not fit correctly in this case?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好吧,我完全不知道,但你可以尝试一下,将宽度更改为 0dp 并在 xml 中添加此行并尝试
Well I exactly don't know but you can give it a try by changing the width to 0dp and add this line in your xml and try