[英]ConstraintLayout in NavigationView header doesn't take full width
NavigationView
: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
: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. android:
ConstraintLayout
的android:layout_width="match_parent"
不工作。 Header width is less then NavigationView
. Header 宽度小于
NavigationView
。
When I'm trying to replace ConstraintLayout
to LinearLayout
, width
is correct.当我尝试将
ConstraintLayout
替换为LinearLayout
时, width
是正确的。
Can somebody help me understand why does ConstraintLayout
not fit correctly in this case?有人可以帮助我理解为什么
ConstraintLayout
在这种情况下不适合吗?
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好吧,我完全不知道,但你可以通过将宽度更改为 0dp 来尝试一下,并将这一行添加到你的 xml 中并尝试
android:layout_width="0dp"
app:layout_constraintWidth_percent="1"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.