如何解决当我将其放入ConstraintLayout时,不会显示LinearLayout
我有一个带有Deferents视图的LinearLayout,将其安装在手机中时,它可以正常显示。但是我想将LinearLayout放到ContraintLayout中,但是当我这样做时,屏幕上什么也没显示。
此代码效果很好
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto">
<data>
</data>
<LinearLayout
android:id="@+id/bottomMenu"
android:layout_width="match_parent"
android:layout_height="@dimen/short_cuts_bottom_menu_layout_height"
android:orientation="vertical"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<!-- Views -->
</LinearLayout>
</layout>
但这不起作用
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto">
<data>
</data>
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<LinearLayout
android:id="@+id/bottomMenu"
android:layout_width="match_parent"
android:layout_height="@dimen/short_cuts_bottom_menu_layout_height"
android:orientation="vertical"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<!-- Views -->
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
</layout>
然后我将我的LinearLayout放入ConstraintLayout
有人知道为什么会这样吗?
解决方法
android:layout_width
中的ConstraintLayout
属性应具有值match_parent
,因为其中的LinearLayout
具有相同的值
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
,
通过将 wrap_content 分配给ConstraintLayout的宽度,您可以告诉它根据其子项的尺寸定义其尺寸。通过将 match_parent 分配给LinearLayout的宽度,您可以告诉它根据其父级定义其尺寸。所以他们一直互相问,没人知道:)
您可以简单地将 match_parent 分配给约束布局的宽度
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。