There is a ConstraintLayout
layout:
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:id="@+id/button10"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
android:singleLine="true"
android:text="small text"
app:layout_constraintLeft_toLeftOf="parent"/>
<Button
android:ellipsize="end"
android:singleLine="true"
android:id="@+id/button11"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="small text"
app:layout_constraintRight_toRightOf="parent"/>
</android.support.constraint.ConstraintLayout>
It is displayed like this:
Now is Ok, but if i change
android:text="small text"
to android:text="big teeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeext"
then views will overlap each other..
I’m need to make sure that with a small text there is a “wrap content”, as I actually did on the screenshot above, but with a larger text, the text views must occupy a maximum of about 40 percent horizontally of the parent. Well also that the text was not transferred – I do android: ellipsize =" end "
and android: singleLine =" true
.
This is how it should be (edited in Photoshop for demonstration):
How do this with ConstraintLayout or if can’t – with others layouts?
5
Answers
you can also do it using Guideline and layout_constraintWidth_default property as in below example
The following attribute works:
https://developer.android.com/reference/android/support/constraint/ConstraintLayout
If constraint is from left/right
If constraint is from top/bottom
I would suggest to use a horizontal chain and a ‘app:layout_constraintWidth_percent’.
The ‘spread_inside’ chain type would make the buttons stick to the parent edges, it’s added on the first button in chain.
The guidelines role is performed by the ‘app:layout_constraintWidth_percent’ on each button. It is set to 0.5 on both buttons. This will make each of them occupy maximum half of the available horizontal space.