Reputation: 63
I have a LinearLayout with deferents views, and it displays normally when install it in my phone. But I want to put that LinearLayout into a ContraintLayout, however when I did it, nothing is display in my screen.
This code works well
<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>
But this doesn't works
<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>
And I just put my LinearLayout into a ConstraintLayout
Someone knows why this happens?
Upvotes: 0
Views: 424
Reputation: 2516
By assigning wrap_content to the width of your ConstraintLayout, you tell it to define its dimension based on the dimensions of its children. And by assigning match_parent to the width of your LinearLayout you tell it to define its dimension based on its parent. So they keep asking each other, nobody knows :)
You can simply assign match_parent to the width of your constraint layout
Upvotes: 1
Reputation: 4951
The android:layout_width
attribute in ConstraintLayout
should have the value match_parent
because the LinearLayout
inside it has the same
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
Upvotes: 1