Avoid overlap in ConstraintLayout
I have the following layout:
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="10dp">
<TextView
android:id="@+id/itemKey"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/black"
app:layout_constraintStart_toStartOf="parent"
tools:text="Recipient:"/>
<TextView
android:id="@+id/itemValue"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
android:maxLines="1"
android:textColor="@color/black"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintLeft_toRightOf="@id/itemKey"
tools:text="loooooooooonnnnnnngemmmmmmmmaaaaaaaiiilll@gmail.com"/>
</android.support.constraint.ConstraintLayout>
And this is how it shows up:
It should really be:
What do I need to fix this? I've tried using guidelines and horizontal bias, and also tried constraining it with RelativeLayout instead of a ConstraintLayout, but nothing has helped so far.
android android-layout android-constraintlayout
add a comment |
I have the following layout:
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="10dp">
<TextView
android:id="@+id/itemKey"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/black"
app:layout_constraintStart_toStartOf="parent"
tools:text="Recipient:"/>
<TextView
android:id="@+id/itemValue"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
android:maxLines="1"
android:textColor="@color/black"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintLeft_toRightOf="@id/itemKey"
tools:text="loooooooooonnnnnnngemmmmmmmmaaaaaaaiiilll@gmail.com"/>
</android.support.constraint.ConstraintLayout>
And this is how it shows up:
It should really be:
What do I need to fix this? I've tried using guidelines and horizontal bias, and also tried constraining it with RelativeLayout instead of a ConstraintLayout, but nothing has helped so far.
android android-layout android-constraintlayout
add a comment |
I have the following layout:
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="10dp">
<TextView
android:id="@+id/itemKey"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/black"
app:layout_constraintStart_toStartOf="parent"
tools:text="Recipient:"/>
<TextView
android:id="@+id/itemValue"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
android:maxLines="1"
android:textColor="@color/black"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintLeft_toRightOf="@id/itemKey"
tools:text="loooooooooonnnnnnngemmmmmmmmaaaaaaaiiilll@gmail.com"/>
</android.support.constraint.ConstraintLayout>
And this is how it shows up:
It should really be:
What do I need to fix this? I've tried using guidelines and horizontal bias, and also tried constraining it with RelativeLayout instead of a ConstraintLayout, but nothing has helped so far.
android android-layout android-constraintlayout
I have the following layout:
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="10dp">
<TextView
android:id="@+id/itemKey"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/black"
app:layout_constraintStart_toStartOf="parent"
tools:text="Recipient:"/>
<TextView
android:id="@+id/itemValue"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
android:maxLines="1"
android:textColor="@color/black"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintLeft_toRightOf="@id/itemKey"
tools:text="loooooooooonnnnnnngemmmmmmmmaaaaaaaiiilll@gmail.com"/>
</android.support.constraint.ConstraintLayout>
And this is how it shows up:
It should really be:
What do I need to fix this? I've tried using guidelines and horizontal bias, and also tried constraining it with RelativeLayout instead of a ConstraintLayout, but nothing has helped so far.
android android-layout android-constraintlayout
android android-layout android-constraintlayout
asked Nov 22 '18 at 0:51
rajathrajath
8,99063453
8,99063453
add a comment |
add a comment |
3 Answers
3
active
oldest
votes
You could try setting itemValue
width to 0 and use layout_constraintStart_toEndOf
instead:
<TextView
android:id="@+id/itemValue"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:ellipsize="end"
android:maxLines="1"
android:textColor="@color/black"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@id/itemKey"
tools:text="loooooooooonnnnnnngemmmmmmmmaaaaaaaiiilll@gmail.com"/>
You may need to use android:gravity="right|end"
if you intend to align the text to the end.
1
Thank you, Aaron. Although there are other answers which worked as well, your suggestion to use thegravity
flag clinched it for me.
– rajath
Nov 22 '18 at 3:44
add a comment |
This should solve your problem. If you want the text to take the next line you can remove the maxLines=1
condition.
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="10dp">
<TextView
android:id="@+id/itemKey"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@android:color/black"
app:layout_constraintStart_toStartOf="parent"
tools:text="Recipient:"/>
<TextView
android:id="@+id/itemValue"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:ellipsize="end"
android:maxLines="1"
android:textColor="@android:color/black"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@id/itemKey"
tools:text="loooooooooonnnnnnngemmmmmmmmaaaaaaaiiilll@gmail.com"/>
</android.support.constraint.ConstraintLayout>
add a comment |
If you don't care about having the second view's width be wrap_content
, you can make some small changes. Make the width 0dp
instead of wrap_content
and change app:layout_constraintLeft_toRightOf
to app:layout_constraintStart_toEndOf
(with the same value). This will make the view always be exactly as large as the remaining horizontal space:
If you need wrap_content
behavior, then you can do the same as above but additionally add these two attributes:
app:layout_constraintHorizontal_bias="0"
app:layout_constraintWidth_default="wrap"
Here it is all together:
<TextView
android:id="@+id/itemValue"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:ellipsize="end"
android:maxLines="1"
android:textColor="@color/black"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0"
app:layout_constraintStart_toEndOf="@id/itemKey"
app:layout_constraintWidth_default="wrap"
tools:text="loooooooooonnnnnnngemmmmmmmmaaaaaaaiiilll@gmail.com" />
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53422468%2favoid-overlap-in-constraintlayout%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
You could try setting itemValue
width to 0 and use layout_constraintStart_toEndOf
instead:
<TextView
android:id="@+id/itemValue"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:ellipsize="end"
android:maxLines="1"
android:textColor="@color/black"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@id/itemKey"
tools:text="loooooooooonnnnnnngemmmmmmmmaaaaaaaiiilll@gmail.com"/>
You may need to use android:gravity="right|end"
if you intend to align the text to the end.
1
Thank you, Aaron. Although there are other answers which worked as well, your suggestion to use thegravity
flag clinched it for me.
– rajath
Nov 22 '18 at 3:44
add a comment |
You could try setting itemValue
width to 0 and use layout_constraintStart_toEndOf
instead:
<TextView
android:id="@+id/itemValue"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:ellipsize="end"
android:maxLines="1"
android:textColor="@color/black"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@id/itemKey"
tools:text="loooooooooonnnnnnngemmmmmmmmaaaaaaaiiilll@gmail.com"/>
You may need to use android:gravity="right|end"
if you intend to align the text to the end.
1
Thank you, Aaron. Although there are other answers which worked as well, your suggestion to use thegravity
flag clinched it for me.
– rajath
Nov 22 '18 at 3:44
add a comment |
You could try setting itemValue
width to 0 and use layout_constraintStart_toEndOf
instead:
<TextView
android:id="@+id/itemValue"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:ellipsize="end"
android:maxLines="1"
android:textColor="@color/black"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@id/itemKey"
tools:text="loooooooooonnnnnnngemmmmmmmmaaaaaaaiiilll@gmail.com"/>
You may need to use android:gravity="right|end"
if you intend to align the text to the end.
You could try setting itemValue
width to 0 and use layout_constraintStart_toEndOf
instead:
<TextView
android:id="@+id/itemValue"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:ellipsize="end"
android:maxLines="1"
android:textColor="@color/black"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@id/itemKey"
tools:text="loooooooooonnnnnnngemmmmmmmmaaaaaaaiiilll@gmail.com"/>
You may need to use android:gravity="right|end"
if you intend to align the text to the end.
answered Nov 22 '18 at 1:02
AaronAaron
1,8282213
1,8282213
1
Thank you, Aaron. Although there are other answers which worked as well, your suggestion to use thegravity
flag clinched it for me.
– rajath
Nov 22 '18 at 3:44
add a comment |
1
Thank you, Aaron. Although there are other answers which worked as well, your suggestion to use thegravity
flag clinched it for me.
– rajath
Nov 22 '18 at 3:44
1
1
Thank you, Aaron. Although there are other answers which worked as well, your suggestion to use the
gravity
flag clinched it for me.– rajath
Nov 22 '18 at 3:44
Thank you, Aaron. Although there are other answers which worked as well, your suggestion to use the
gravity
flag clinched it for me.– rajath
Nov 22 '18 at 3:44
add a comment |
This should solve your problem. If you want the text to take the next line you can remove the maxLines=1
condition.
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="10dp">
<TextView
android:id="@+id/itemKey"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@android:color/black"
app:layout_constraintStart_toStartOf="parent"
tools:text="Recipient:"/>
<TextView
android:id="@+id/itemValue"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:ellipsize="end"
android:maxLines="1"
android:textColor="@android:color/black"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@id/itemKey"
tools:text="loooooooooonnnnnnngemmmmmmmmaaaaaaaiiilll@gmail.com"/>
</android.support.constraint.ConstraintLayout>
add a comment |
This should solve your problem. If you want the text to take the next line you can remove the maxLines=1
condition.
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="10dp">
<TextView
android:id="@+id/itemKey"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@android:color/black"
app:layout_constraintStart_toStartOf="parent"
tools:text="Recipient:"/>
<TextView
android:id="@+id/itemValue"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:ellipsize="end"
android:maxLines="1"
android:textColor="@android:color/black"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@id/itemKey"
tools:text="loooooooooonnnnnnngemmmmmmmmaaaaaaaiiilll@gmail.com"/>
</android.support.constraint.ConstraintLayout>
add a comment |
This should solve your problem. If you want the text to take the next line you can remove the maxLines=1
condition.
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="10dp">
<TextView
android:id="@+id/itemKey"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@android:color/black"
app:layout_constraintStart_toStartOf="parent"
tools:text="Recipient:"/>
<TextView
android:id="@+id/itemValue"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:ellipsize="end"
android:maxLines="1"
android:textColor="@android:color/black"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@id/itemKey"
tools:text="loooooooooonnnnnnngemmmmmmmmaaaaaaaiiilll@gmail.com"/>
</android.support.constraint.ConstraintLayout>
This should solve your problem. If you want the text to take the next line you can remove the maxLines=1
condition.
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="10dp">
<TextView
android:id="@+id/itemKey"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@android:color/black"
app:layout_constraintStart_toStartOf="parent"
tools:text="Recipient:"/>
<TextView
android:id="@+id/itemValue"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:ellipsize="end"
android:maxLines="1"
android:textColor="@android:color/black"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@id/itemKey"
tools:text="loooooooooonnnnnnngemmmmmmmmaaaaaaaiiilll@gmail.com"/>
</android.support.constraint.ConstraintLayout>
answered Nov 22 '18 at 2:06
ASNASN
5561832
5561832
add a comment |
add a comment |
If you don't care about having the second view's width be wrap_content
, you can make some small changes. Make the width 0dp
instead of wrap_content
and change app:layout_constraintLeft_toRightOf
to app:layout_constraintStart_toEndOf
(with the same value). This will make the view always be exactly as large as the remaining horizontal space:
If you need wrap_content
behavior, then you can do the same as above but additionally add these two attributes:
app:layout_constraintHorizontal_bias="0"
app:layout_constraintWidth_default="wrap"
Here it is all together:
<TextView
android:id="@+id/itemValue"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:ellipsize="end"
android:maxLines="1"
android:textColor="@color/black"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0"
app:layout_constraintStart_toEndOf="@id/itemKey"
app:layout_constraintWidth_default="wrap"
tools:text="loooooooooonnnnnnngemmmmmmmmaaaaaaaiiilll@gmail.com" />
add a comment |
If you don't care about having the second view's width be wrap_content
, you can make some small changes. Make the width 0dp
instead of wrap_content
and change app:layout_constraintLeft_toRightOf
to app:layout_constraintStart_toEndOf
(with the same value). This will make the view always be exactly as large as the remaining horizontal space:
If you need wrap_content
behavior, then you can do the same as above but additionally add these two attributes:
app:layout_constraintHorizontal_bias="0"
app:layout_constraintWidth_default="wrap"
Here it is all together:
<TextView
android:id="@+id/itemValue"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:ellipsize="end"
android:maxLines="1"
android:textColor="@color/black"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0"
app:layout_constraintStart_toEndOf="@id/itemKey"
app:layout_constraintWidth_default="wrap"
tools:text="loooooooooonnnnnnngemmmmmmmmaaaaaaaiiilll@gmail.com" />
add a comment |
If you don't care about having the second view's width be wrap_content
, you can make some small changes. Make the width 0dp
instead of wrap_content
and change app:layout_constraintLeft_toRightOf
to app:layout_constraintStart_toEndOf
(with the same value). This will make the view always be exactly as large as the remaining horizontal space:
If you need wrap_content
behavior, then you can do the same as above but additionally add these two attributes:
app:layout_constraintHorizontal_bias="0"
app:layout_constraintWidth_default="wrap"
Here it is all together:
<TextView
android:id="@+id/itemValue"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:ellipsize="end"
android:maxLines="1"
android:textColor="@color/black"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0"
app:layout_constraintStart_toEndOf="@id/itemKey"
app:layout_constraintWidth_default="wrap"
tools:text="loooooooooonnnnnnngemmmmmmmmaaaaaaaiiilll@gmail.com" />
If you don't care about having the second view's width be wrap_content
, you can make some small changes. Make the width 0dp
instead of wrap_content
and change app:layout_constraintLeft_toRightOf
to app:layout_constraintStart_toEndOf
(with the same value). This will make the view always be exactly as large as the remaining horizontal space:
If you need wrap_content
behavior, then you can do the same as above but additionally add these two attributes:
app:layout_constraintHorizontal_bias="0"
app:layout_constraintWidth_default="wrap"
Here it is all together:
<TextView
android:id="@+id/itemValue"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:ellipsize="end"
android:maxLines="1"
android:textColor="@color/black"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0"
app:layout_constraintStart_toEndOf="@id/itemKey"
app:layout_constraintWidth_default="wrap"
tools:text="loooooooooonnnnnnngemmmmmmmmaaaaaaaiiilll@gmail.com" />
answered Nov 22 '18 at 3:08
Ben P.Ben P.
24.9k32252
24.9k32252
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53422468%2favoid-overlap-in-constraintlayout%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown