当我将它放入 ConstraintLayout 时,LinearLayout 不显示
LinearLayout doesn't show when I put it into a ConstraintLayout
我有一个带有不同视图的 LinearLayout,在我的 phone 中安装它时它可以正常显示。但是我想把那个 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
有人知道为什么会这样吗?
ConstraintLayout
中的android:layout_width
属性的值应该是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 分配给约束布局的宽度
我有一个带有不同视图的 LinearLayout,在我的 phone 中安装它时它可以正常显示。但是我想把那个 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
有人知道为什么会这样吗?
ConstraintLayout
中的android:layout_width
属性的值应该是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 分配给约束布局的宽度