New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
constrained width expands the view #713
Comments
wrap_content |
If I use I want |
Try this: <TextView
android:id="@+id/text_view"
android:layout_width="0dp"
android:layout_height="20dp"
android:background="@android:color/holo_purple"
android:ellipsize="end"
android:maxLines="1"
android:textColor="@color/white"
app:layout_constraintWidth_max="wrap"
app:layout_constraintEnd_toEndOf="@id/view_2"
app:layout_constraintStart_toEndOf="@id/view_1"
app:layout_constraintTop_toTopOf="parent"
tools:text="@tools:sample/lorem/random" />
It should give you want you want |
Yeah, that has the desired effect. I'm confused tough, shouldn't my initial code also work? At least I gathered from documentation, that this should be possible. |
This has to do with priorities - who wins the "fight between wrap and constraints" in various scenarios. It is hard to explain and ends up being super confusing in the documentation unless you encounter your type of problem. Some percentage of people approach the problem from with=0dp and never think about the subtlety. |
is lack of space. Previously: There was a chain [date]-[space]-[status icons]-[battery]. That's why we should add bias and space to make it working. But there're several problems with this: 1) app:layout_width="WRAP_CONTENT" + app:layout_constrainedWidth=”true" != app:layout_width="0dp" + app:layout_constraintWidth_default="wrap". The first one gets view expanded like it's MATCH_PARENT. 2) I've found out that wrapping views in constraint layout 2.0.0 may not always work as expected with app:layout_constrainedWidth=”true" (the view get's stretched as it's match_parent). layout_constraintWidth_max="wrap" should've help with this, but motion layout can't parse this attribute in constraint set. That's why my solution is to reimplement the layout a little bit This behavior is reported here: androidx/constraintlayout#713 Now: [date] and [battery] are constrained to the sides and [status icons] occupy the whole space between them. [date] is always WRAP_CONTENT because there's always some space and we want to show it. [battery] and [status icons] are wrap content with constraints restrictions to make them fill all the space left Test: manual: phone + tablet Fixes: 260364389 Change-Id: I4d54b795cc4e96f6c204f2f00aff7607572d9aa3 (cherry picked from commit 675ff0f) Merged-In: I4d54b795cc4e96f6c204f2f00aff7607572d9aa3
is lack of space. Previously: There was a chain [date]-[space]-[status icons]-[battery]. That's why we should add bias and space to make it working. But there're several problems with this: 1) app:layout_width="WRAP_CONTENT" + app:layout_constrainedWidth=”true" != app:layout_width="0dp" + app:layout_constraintWidth_default="wrap". The first one gets view expanded like it's MATCH_PARENT. 2) I've found out that wrapping views in constraint layout 2.0.0 may not always work as expected with app:layout_constrainedWidth=”true" (the view get's stretched as it's match_parent). layout_constraintWidth_max="wrap" should've help with this, but motion layout can't parse this attribute in constraint set. That's why my solution is to reimplement the layout a little bit This behavior is reported here: androidx/constraintlayout#713 Now: [date] and [battery] are constrained to the sides and [status icons] occupy the whole space between them. [date] is always WRAP_CONTENT because there's always some space and we want to show it. [battery] and [status icons] are wrap content with constraints restrictions to make them fill all the space left Test: manual: phone + tablet Fixes: 260364389 Change-Id: I4d54b795cc4e96f6c204f2f00aff7607572d9aa3
Issue
When
layout_constrainedWidth
is set totrue
, it can expand parent layout.Use case
I'm trying to achieve following layout. I want
text_view
to expand until it's limitied by size ofview_2
.But when
layout_constrainedWidth
is set, it expands whole parent:Versions
androidx.constraintlayout:constraintlayout:2.1.4
The text was updated successfully, but these errors were encountered: