TextView going out of screen with constraintLayout
I am using ConstraintLayout
to create below xml in my application.
As you can see my first item is fine, But in the second one, some parts of my textView
are not on the screen!
This is my XML
code:
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/ly_user"
android:padding="8dp"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
app:layout_constraintRight_toRightOf="parent"
android:id="@+id/im_user_icon"
android:layout_width="@dimen/default_message_icon_size"
android:layout_height="@dimen/default_message_icon_size"
android:src="@drawable/user_pacific"/>
<ImageView
app:layout_constraintTop_toBottomOf="@+id/im_user_icon"
app:layout_constraintRight_toLeftOf="@+id/im_user_icon"
android:id="@+id/im_user_arrow"
android:layout_width="30dp"
android:layout_height="30dp"
android:src="@drawable/arrow_bg1"/>
<View
android:id="@+id/view_user_guidLine"
android:layout_width="1dp"
android:layout_height="0dp"
app:layout_constraintLeft_toLeftOf="@id/im_user_arrow"
app:layout_constraintRight_toRightOf="@id/im_user_arrow"/>
<TextView
app:layout_constraintTop_toBottomOf="@+id/im_user_icon"
app:layout_constraintRight_toLeftOf="@+id/view_user_guidLine"
android:id="@+id/tv_user_message"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:gravity="right"
android:padding="8dp"
android:minWidth="@dimen/default_message_textarea_width"
android:minHeight="@dimen/default_message_textarea_height"
android:background="@drawable/bg_right_text"
android:textColor="@android:color/white"/>
</android.support.constraint.ConstraintLayout>
I Know I can fix this problem to adding below line to the textView
, But I need my textView
be wrapContent
.
app:layout_constraintLeft_toLeftOf="parent"
android android-layout android-constraintlayout
add a comment |
I am using ConstraintLayout
to create below xml in my application.
As you can see my first item is fine, But in the second one, some parts of my textView
are not on the screen!
This is my XML
code:
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/ly_user"
android:padding="8dp"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
app:layout_constraintRight_toRightOf="parent"
android:id="@+id/im_user_icon"
android:layout_width="@dimen/default_message_icon_size"
android:layout_height="@dimen/default_message_icon_size"
android:src="@drawable/user_pacific"/>
<ImageView
app:layout_constraintTop_toBottomOf="@+id/im_user_icon"
app:layout_constraintRight_toLeftOf="@+id/im_user_icon"
android:id="@+id/im_user_arrow"
android:layout_width="30dp"
android:layout_height="30dp"
android:src="@drawable/arrow_bg1"/>
<View
android:id="@+id/view_user_guidLine"
android:layout_width="1dp"
android:layout_height="0dp"
app:layout_constraintLeft_toLeftOf="@id/im_user_arrow"
app:layout_constraintRight_toRightOf="@id/im_user_arrow"/>
<TextView
app:layout_constraintTop_toBottomOf="@+id/im_user_icon"
app:layout_constraintRight_toLeftOf="@+id/view_user_guidLine"
android:id="@+id/tv_user_message"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:gravity="right"
android:padding="8dp"
android:minWidth="@dimen/default_message_textarea_width"
android:minHeight="@dimen/default_message_textarea_height"
android:background="@drawable/bg_right_text"
android:textColor="@android:color/white"/>
</android.support.constraint.ConstraintLayout>
I Know I can fix this problem to adding below line to the textView
, But I need my textView
be wrapContent
.
app:layout_constraintLeft_toLeftOf="parent"
android android-layout android-constraintlayout
I think you should align the container of the text view according to width. If that is done, then, TextView should fit in correctly.
– bengongon97
Jan 1 at 9:34
Using maxWidth you can do this. I see already you applied but it should work.
– Shweta Chauhan
Jan 1 at 9:43
add a comment |
I am using ConstraintLayout
to create below xml in my application.
As you can see my first item is fine, But in the second one, some parts of my textView
are not on the screen!
This is my XML
code:
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/ly_user"
android:padding="8dp"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
app:layout_constraintRight_toRightOf="parent"
android:id="@+id/im_user_icon"
android:layout_width="@dimen/default_message_icon_size"
android:layout_height="@dimen/default_message_icon_size"
android:src="@drawable/user_pacific"/>
<ImageView
app:layout_constraintTop_toBottomOf="@+id/im_user_icon"
app:layout_constraintRight_toLeftOf="@+id/im_user_icon"
android:id="@+id/im_user_arrow"
android:layout_width="30dp"
android:layout_height="30dp"
android:src="@drawable/arrow_bg1"/>
<View
android:id="@+id/view_user_guidLine"
android:layout_width="1dp"
android:layout_height="0dp"
app:layout_constraintLeft_toLeftOf="@id/im_user_arrow"
app:layout_constraintRight_toRightOf="@id/im_user_arrow"/>
<TextView
app:layout_constraintTop_toBottomOf="@+id/im_user_icon"
app:layout_constraintRight_toLeftOf="@+id/view_user_guidLine"
android:id="@+id/tv_user_message"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:gravity="right"
android:padding="8dp"
android:minWidth="@dimen/default_message_textarea_width"
android:minHeight="@dimen/default_message_textarea_height"
android:background="@drawable/bg_right_text"
android:textColor="@android:color/white"/>
</android.support.constraint.ConstraintLayout>
I Know I can fix this problem to adding below line to the textView
, But I need my textView
be wrapContent
.
app:layout_constraintLeft_toLeftOf="parent"
android android-layout android-constraintlayout
I am using ConstraintLayout
to create below xml in my application.
As you can see my first item is fine, But in the second one, some parts of my textView
are not on the screen!
This is my XML
code:
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/ly_user"
android:padding="8dp"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
app:layout_constraintRight_toRightOf="parent"
android:id="@+id/im_user_icon"
android:layout_width="@dimen/default_message_icon_size"
android:layout_height="@dimen/default_message_icon_size"
android:src="@drawable/user_pacific"/>
<ImageView
app:layout_constraintTop_toBottomOf="@+id/im_user_icon"
app:layout_constraintRight_toLeftOf="@+id/im_user_icon"
android:id="@+id/im_user_arrow"
android:layout_width="30dp"
android:layout_height="30dp"
android:src="@drawable/arrow_bg1"/>
<View
android:id="@+id/view_user_guidLine"
android:layout_width="1dp"
android:layout_height="0dp"
app:layout_constraintLeft_toLeftOf="@id/im_user_arrow"
app:layout_constraintRight_toRightOf="@id/im_user_arrow"/>
<TextView
app:layout_constraintTop_toBottomOf="@+id/im_user_icon"
app:layout_constraintRight_toLeftOf="@+id/view_user_guidLine"
android:id="@+id/tv_user_message"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:gravity="right"
android:padding="8dp"
android:minWidth="@dimen/default_message_textarea_width"
android:minHeight="@dimen/default_message_textarea_height"
android:background="@drawable/bg_right_text"
android:textColor="@android:color/white"/>
</android.support.constraint.ConstraintLayout>
I Know I can fix this problem to adding below line to the textView
, But I need my textView
be wrapContent
.
app:layout_constraintLeft_toLeftOf="parent"
android android-layout android-constraintlayout
android android-layout android-constraintlayout
edited Jan 1 at 9:25
ADM
8,797102352
8,797102352
asked Jan 1 at 9:10
EhsanEhsan
531727
531727
I think you should align the container of the text view according to width. If that is done, then, TextView should fit in correctly.
– bengongon97
Jan 1 at 9:34
Using maxWidth you can do this. I see already you applied but it should work.
– Shweta Chauhan
Jan 1 at 9:43
add a comment |
I think you should align the container of the text view according to width. If that is done, then, TextView should fit in correctly.
– bengongon97
Jan 1 at 9:34
Using maxWidth you can do this. I see already you applied but it should work.
– Shweta Chauhan
Jan 1 at 9:43
I think you should align the container of the text view according to width. If that is done, then, TextView should fit in correctly.
– bengongon97
Jan 1 at 9:34
I think you should align the container of the text view according to width. If that is done, then, TextView should fit in correctly.
– bengongon97
Jan 1 at 9:34
Using maxWidth you can do this. I see already you applied but it should work.
– Shweta Chauhan
Jan 1 at 9:43
Using maxWidth you can do this. I see already you applied but it should work.
– Shweta Chauhan
Jan 1 at 9:43
add a comment |
2 Answers
2
active
oldest
votes
You can set your TextView's
width to wrap_content
, but to prevent it from expanding outside of screen you need to add the left constraint as well and use app:layout_constrainedWidth="true"
to enforce constraints.
Now, to make the TextView
stick to the right, you need to add app:layout_constraintHorizontal_bias="1"
, which will align it to its right constraint.
So all in all, these are the changes needed for the TextView
:
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constrainedWidth="true"
app:layout_constraintHorizontal_bias="1"
android:layout_width="wrap_content"
add a comment |
Add these following line in your code in your TextView
app:layout_constraintWidth_percent="0.6"
first line layout_constraintWidth_percent
is 60 percent of your phone screen width you can change it according to your need.
this works but all the time takes 0.6 of screen, But I want it to be wrap_content
– Ehsan
Jan 2 at 5:55
I know, But I need my textView be wrap content all the time
– Ehsan
Jan 2 at 6:09
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%2f53994248%2ftextview-going-out-of-screen-with-constraintlayout%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
You can set your TextView's
width to wrap_content
, but to prevent it from expanding outside of screen you need to add the left constraint as well and use app:layout_constrainedWidth="true"
to enforce constraints.
Now, to make the TextView
stick to the right, you need to add app:layout_constraintHorizontal_bias="1"
, which will align it to its right constraint.
So all in all, these are the changes needed for the TextView
:
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constrainedWidth="true"
app:layout_constraintHorizontal_bias="1"
android:layout_width="wrap_content"
add a comment |
You can set your TextView's
width to wrap_content
, but to prevent it from expanding outside of screen you need to add the left constraint as well and use app:layout_constrainedWidth="true"
to enforce constraints.
Now, to make the TextView
stick to the right, you need to add app:layout_constraintHorizontal_bias="1"
, which will align it to its right constraint.
So all in all, these are the changes needed for the TextView
:
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constrainedWidth="true"
app:layout_constraintHorizontal_bias="1"
android:layout_width="wrap_content"
add a comment |
You can set your TextView's
width to wrap_content
, but to prevent it from expanding outside of screen you need to add the left constraint as well and use app:layout_constrainedWidth="true"
to enforce constraints.
Now, to make the TextView
stick to the right, you need to add app:layout_constraintHorizontal_bias="1"
, which will align it to its right constraint.
So all in all, these are the changes needed for the TextView
:
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constrainedWidth="true"
app:layout_constraintHorizontal_bias="1"
android:layout_width="wrap_content"
You can set your TextView's
width to wrap_content
, but to prevent it from expanding outside of screen you need to add the left constraint as well and use app:layout_constrainedWidth="true"
to enforce constraints.
Now, to make the TextView
stick to the right, you need to add app:layout_constraintHorizontal_bias="1"
, which will align it to its right constraint.
So all in all, these are the changes needed for the TextView
:
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constrainedWidth="true"
app:layout_constraintHorizontal_bias="1"
android:layout_width="wrap_content"
answered Jan 1 at 14:47
Pawel LaskowskiPawel Laskowski
1,6671612
1,6671612
add a comment |
add a comment |
Add these following line in your code in your TextView
app:layout_constraintWidth_percent="0.6"
first line layout_constraintWidth_percent
is 60 percent of your phone screen width you can change it according to your need.
this works but all the time takes 0.6 of screen, But I want it to be wrap_content
– Ehsan
Jan 2 at 5:55
I know, But I need my textView be wrap content all the time
– Ehsan
Jan 2 at 6:09
add a comment |
Add these following line in your code in your TextView
app:layout_constraintWidth_percent="0.6"
first line layout_constraintWidth_percent
is 60 percent of your phone screen width you can change it according to your need.
this works but all the time takes 0.6 of screen, But I want it to be wrap_content
– Ehsan
Jan 2 at 5:55
I know, But I need my textView be wrap content all the time
– Ehsan
Jan 2 at 6:09
add a comment |
Add these following line in your code in your TextView
app:layout_constraintWidth_percent="0.6"
first line layout_constraintWidth_percent
is 60 percent of your phone screen width you can change it according to your need.
Add these following line in your code in your TextView
app:layout_constraintWidth_percent="0.6"
first line layout_constraintWidth_percent
is 60 percent of your phone screen width you can change it according to your need.
edited Jan 2 at 4:22
answered Jan 1 at 9:32
Saurabh BhandariSaurabh Bhandari
1,88741825
1,88741825
this works but all the time takes 0.6 of screen, But I want it to be wrap_content
– Ehsan
Jan 2 at 5:55
I know, But I need my textView be wrap content all the time
– Ehsan
Jan 2 at 6:09
add a comment |
this works but all the time takes 0.6 of screen, But I want it to be wrap_content
– Ehsan
Jan 2 at 5:55
I know, But I need my textView be wrap content all the time
– Ehsan
Jan 2 at 6:09
this works but all the time takes 0.6 of screen, But I want it to be wrap_content
– Ehsan
Jan 2 at 5:55
this works but all the time takes 0.6 of screen, But I want it to be wrap_content
– Ehsan
Jan 2 at 5:55
I know, But I need my textView be wrap content all the time
– Ehsan
Jan 2 at 6:09
I know, But I need my textView be wrap content all the time
– Ehsan
Jan 2 at 6:09
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%2f53994248%2ftextview-going-out-of-screen-with-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
I think you should align the container of the text view according to width. If that is done, then, TextView should fit in correctly.
– bengongon97
Jan 1 at 9:34
Using maxWidth you can do this. I see already you applied but it should work.
– Shweta Chauhan
Jan 1 at 9:43