How to force TextView to use as much space as possible on the first line












0















I have a problem with creating a chat layout.



How can I force TextView's text to fill up the entire area?
Even if the string is continuous, sometimes text goes to the next line.



Problem



XML with TextView:



<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.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_marginBottom="4dp"
android:layout_width="match_parent"
android:layout_height="wrap_content">

<TextView
android:id="@+id/my_msg"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/message_my_shape"
android:paddingLeft="16dp"
android:paddingTop="8dp"
android:paddingRight="16dp"
android:paddingBottom="8dp"
android:text="Hey mate,how youre doing?"
android:textColor="#fcc7d3"
android:textSize="16sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toStartOf="parent"
tools:layout_editor_absoluteY="0dp" />

</androidx.constraintlayout.widget.ConstraintLayout>


UPD:
You don't quite get me, guys. Padding should be there and I don't want a single line, please see the new screenshots with layout boundaries shown to see what I'm talking about.
Question is still the same, why text in TextView doesn't fill all available space (sometimes)?
enter image description here



enter image description here










share|improve this question

























  • Remove the padding you have on the TextView.

    – TheWanderer
    Nov 13 '18 at 23:42











  • Thanks for an answer. Unfortunately, This wouldn't work.Please see an updated post

    – Jbwz
    Nov 14 '18 at 0:17











  • I still have no idea what you're asking.

    – TheWanderer
    Nov 14 '18 at 0:18











  • Just answered my own question. Ta

    – Jbwz
    Nov 14 '18 at 0:23
















0















I have a problem with creating a chat layout.



How can I force TextView's text to fill up the entire area?
Even if the string is continuous, sometimes text goes to the next line.



Problem



XML with TextView:



<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.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_marginBottom="4dp"
android:layout_width="match_parent"
android:layout_height="wrap_content">

<TextView
android:id="@+id/my_msg"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/message_my_shape"
android:paddingLeft="16dp"
android:paddingTop="8dp"
android:paddingRight="16dp"
android:paddingBottom="8dp"
android:text="Hey mate,how youre doing?"
android:textColor="#fcc7d3"
android:textSize="16sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toStartOf="parent"
tools:layout_editor_absoluteY="0dp" />

</androidx.constraintlayout.widget.ConstraintLayout>


UPD:
You don't quite get me, guys. Padding should be there and I don't want a single line, please see the new screenshots with layout boundaries shown to see what I'm talking about.
Question is still the same, why text in TextView doesn't fill all available space (sometimes)?
enter image description here



enter image description here










share|improve this question

























  • Remove the padding you have on the TextView.

    – TheWanderer
    Nov 13 '18 at 23:42











  • Thanks for an answer. Unfortunately, This wouldn't work.Please see an updated post

    – Jbwz
    Nov 14 '18 at 0:17











  • I still have no idea what you're asking.

    – TheWanderer
    Nov 14 '18 at 0:18











  • Just answered my own question. Ta

    – Jbwz
    Nov 14 '18 at 0:23














0












0








0








I have a problem with creating a chat layout.



How can I force TextView's text to fill up the entire area?
Even if the string is continuous, sometimes text goes to the next line.



Problem



XML with TextView:



<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.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_marginBottom="4dp"
android:layout_width="match_parent"
android:layout_height="wrap_content">

<TextView
android:id="@+id/my_msg"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/message_my_shape"
android:paddingLeft="16dp"
android:paddingTop="8dp"
android:paddingRight="16dp"
android:paddingBottom="8dp"
android:text="Hey mate,how youre doing?"
android:textColor="#fcc7d3"
android:textSize="16sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toStartOf="parent"
tools:layout_editor_absoluteY="0dp" />

</androidx.constraintlayout.widget.ConstraintLayout>


UPD:
You don't quite get me, guys. Padding should be there and I don't want a single line, please see the new screenshots with layout boundaries shown to see what I'm talking about.
Question is still the same, why text in TextView doesn't fill all available space (sometimes)?
enter image description here



enter image description here










share|improve this question
















I have a problem with creating a chat layout.



How can I force TextView's text to fill up the entire area?
Even if the string is continuous, sometimes text goes to the next line.



Problem



XML with TextView:



<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.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_marginBottom="4dp"
android:layout_width="match_parent"
android:layout_height="wrap_content">

<TextView
android:id="@+id/my_msg"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/message_my_shape"
android:paddingLeft="16dp"
android:paddingTop="8dp"
android:paddingRight="16dp"
android:paddingBottom="8dp"
android:text="Hey mate,how youre doing?"
android:textColor="#fcc7d3"
android:textSize="16sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toStartOf="parent"
tools:layout_editor_absoluteY="0dp" />

</androidx.constraintlayout.widget.ConstraintLayout>


UPD:
You don't quite get me, guys. Padding should be there and I don't want a single line, please see the new screenshots with layout boundaries shown to see what I'm talking about.
Question is still the same, why text in TextView doesn't fill all available space (sometimes)?
enter image description here



enter image description here







android xml textview android-constraintlayout






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 14 '18 at 0:16







Jbwz

















asked Nov 13 '18 at 23:38









JbwzJbwz

4010




4010













  • Remove the padding you have on the TextView.

    – TheWanderer
    Nov 13 '18 at 23:42











  • Thanks for an answer. Unfortunately, This wouldn't work.Please see an updated post

    – Jbwz
    Nov 14 '18 at 0:17











  • I still have no idea what you're asking.

    – TheWanderer
    Nov 14 '18 at 0:18











  • Just answered my own question. Ta

    – Jbwz
    Nov 14 '18 at 0:23



















  • Remove the padding you have on the TextView.

    – TheWanderer
    Nov 13 '18 at 23:42











  • Thanks for an answer. Unfortunately, This wouldn't work.Please see an updated post

    – Jbwz
    Nov 14 '18 at 0:17











  • I still have no idea what you're asking.

    – TheWanderer
    Nov 14 '18 at 0:18











  • Just answered my own question. Ta

    – Jbwz
    Nov 14 '18 at 0:23

















Remove the padding you have on the TextView.

– TheWanderer
Nov 13 '18 at 23:42





Remove the padding you have on the TextView.

– TheWanderer
Nov 13 '18 at 23:42













Thanks for an answer. Unfortunately, This wouldn't work.Please see an updated post

– Jbwz
Nov 14 '18 at 0:17





Thanks for an answer. Unfortunately, This wouldn't work.Please see an updated post

– Jbwz
Nov 14 '18 at 0:17













I still have no idea what you're asking.

– TheWanderer
Nov 14 '18 at 0:18





I still have no idea what you're asking.

– TheWanderer
Nov 14 '18 at 0:18













Just answered my own question. Ta

– Jbwz
Nov 14 '18 at 0:23





Just answered my own question. Ta

– Jbwz
Nov 14 '18 at 0:23












3 Answers
3






active

oldest

votes


















0














This reason why this happens is that you didn't specify that your TextView only has one line.



From the documentation:




android:maxLines



Makes the TextView be at most this many lines tall. When used on an
editable text, the inputType attribute's value must be combined with
the textMultiLine flag for the maxLines attribute to apply.




So if you want to always have a single line of text use:



android:maxLines=1




Anything this to your code:



<TextView
android:id="@+id/my_msg"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/message_my_shape"
android:paddingLeft="16dp"
android:paddingTop="8dp"
android:paddingRight="16dp"
android:paddingBottom="8dp"
android:text="Hey mate,how youre doing?"
android:textColor="#fcc7d3"
android:textSize="16sp"
android:maxLines=1
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toStartOf="parent"
tools:layout_editor_absoluteY="0dp" />





share|improve this answer
























  • Thanks for an answer. Unfortunately, This is not the case, It needs to be multiline. Please see an updated post

    – Jbwz
    Nov 14 '18 at 0:17



















0














Found a solution.



For API 23 and higher add to your TextView:



android:breakStrategy="simple"


For API < 23 remove hidden &nbsp; from you text dynamically (android adds them automatically).






share|improve this answer

































    0














    code is correct give the space between the words



    not : "jhjhhjhjhhjhddfhdjfdfdfgdjdjfdj"



    try : Hey mate,how youre doing how are youre doing how youre doing how youre doing ?



    android:layout_width="match_parent" // if needed






    share|improve this answer

























      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
      });


      }
      });














      draft saved

      draft discarded


















      StackExchange.ready(
      function () {
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53291074%2fhow-to-force-textview-to-use-as-much-space-as-possible-on-the-first-line%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









      0














      This reason why this happens is that you didn't specify that your TextView only has one line.



      From the documentation:




      android:maxLines



      Makes the TextView be at most this many lines tall. When used on an
      editable text, the inputType attribute's value must be combined with
      the textMultiLine flag for the maxLines attribute to apply.




      So if you want to always have a single line of text use:



      android:maxLines=1




      Anything this to your code:



      <TextView
      android:id="@+id/my_msg"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:background="@drawable/message_my_shape"
      android:paddingLeft="16dp"
      android:paddingTop="8dp"
      android:paddingRight="16dp"
      android:paddingBottom="8dp"
      android:text="Hey mate,how youre doing?"
      android:textColor="#fcc7d3"
      android:textSize="16sp"
      android:maxLines=1
      app:layout_constraintEnd_toEndOf="parent"
      app:layout_constraintHorizontal_bias="1.0"
      app:layout_constraintStart_toStartOf="parent"
      tools:layout_editor_absoluteY="0dp" />





      share|improve this answer
























      • Thanks for an answer. Unfortunately, This is not the case, It needs to be multiline. Please see an updated post

        – Jbwz
        Nov 14 '18 at 0:17
















      0














      This reason why this happens is that you didn't specify that your TextView only has one line.



      From the documentation:




      android:maxLines



      Makes the TextView be at most this many lines tall. When used on an
      editable text, the inputType attribute's value must be combined with
      the textMultiLine flag for the maxLines attribute to apply.




      So if you want to always have a single line of text use:



      android:maxLines=1




      Anything this to your code:



      <TextView
      android:id="@+id/my_msg"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:background="@drawable/message_my_shape"
      android:paddingLeft="16dp"
      android:paddingTop="8dp"
      android:paddingRight="16dp"
      android:paddingBottom="8dp"
      android:text="Hey mate,how youre doing?"
      android:textColor="#fcc7d3"
      android:textSize="16sp"
      android:maxLines=1
      app:layout_constraintEnd_toEndOf="parent"
      app:layout_constraintHorizontal_bias="1.0"
      app:layout_constraintStart_toStartOf="parent"
      tools:layout_editor_absoluteY="0dp" />





      share|improve this answer
























      • Thanks for an answer. Unfortunately, This is not the case, It needs to be multiline. Please see an updated post

        – Jbwz
        Nov 14 '18 at 0:17














      0












      0








      0







      This reason why this happens is that you didn't specify that your TextView only has one line.



      From the documentation:




      android:maxLines



      Makes the TextView be at most this many lines tall. When used on an
      editable text, the inputType attribute's value must be combined with
      the textMultiLine flag for the maxLines attribute to apply.




      So if you want to always have a single line of text use:



      android:maxLines=1




      Anything this to your code:



      <TextView
      android:id="@+id/my_msg"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:background="@drawable/message_my_shape"
      android:paddingLeft="16dp"
      android:paddingTop="8dp"
      android:paddingRight="16dp"
      android:paddingBottom="8dp"
      android:text="Hey mate,how youre doing?"
      android:textColor="#fcc7d3"
      android:textSize="16sp"
      android:maxLines=1
      app:layout_constraintEnd_toEndOf="parent"
      app:layout_constraintHorizontal_bias="1.0"
      app:layout_constraintStart_toStartOf="parent"
      tools:layout_editor_absoluteY="0dp" />





      share|improve this answer













      This reason why this happens is that you didn't specify that your TextView only has one line.



      From the documentation:




      android:maxLines



      Makes the TextView be at most this many lines tall. When used on an
      editable text, the inputType attribute's value must be combined with
      the textMultiLine flag for the maxLines attribute to apply.




      So if you want to always have a single line of text use:



      android:maxLines=1




      Anything this to your code:



      <TextView
      android:id="@+id/my_msg"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:background="@drawable/message_my_shape"
      android:paddingLeft="16dp"
      android:paddingTop="8dp"
      android:paddingRight="16dp"
      android:paddingBottom="8dp"
      android:text="Hey mate,how youre doing?"
      android:textColor="#fcc7d3"
      android:textSize="16sp"
      android:maxLines=1
      app:layout_constraintEnd_toEndOf="parent"
      app:layout_constraintHorizontal_bias="1.0"
      app:layout_constraintStart_toStartOf="parent"
      tools:layout_editor_absoluteY="0dp" />






      share|improve this answer












      share|improve this answer



      share|improve this answer










      answered Nov 13 '18 at 23:49









      André SousaAndré Sousa

      1,1581818




      1,1581818













      • Thanks for an answer. Unfortunately, This is not the case, It needs to be multiline. Please see an updated post

        – Jbwz
        Nov 14 '18 at 0:17



















      • Thanks for an answer. Unfortunately, This is not the case, It needs to be multiline. Please see an updated post

        – Jbwz
        Nov 14 '18 at 0:17

















      Thanks for an answer. Unfortunately, This is not the case, It needs to be multiline. Please see an updated post

      – Jbwz
      Nov 14 '18 at 0:17





      Thanks for an answer. Unfortunately, This is not the case, It needs to be multiline. Please see an updated post

      – Jbwz
      Nov 14 '18 at 0:17













      0














      Found a solution.



      For API 23 and higher add to your TextView:



      android:breakStrategy="simple"


      For API < 23 remove hidden &nbsp; from you text dynamically (android adds them automatically).






      share|improve this answer






























        0














        Found a solution.



        For API 23 and higher add to your TextView:



        android:breakStrategy="simple"


        For API < 23 remove hidden &nbsp; from you text dynamically (android adds them automatically).






        share|improve this answer




























          0












          0








          0







          Found a solution.



          For API 23 and higher add to your TextView:



          android:breakStrategy="simple"


          For API < 23 remove hidden &nbsp; from you text dynamically (android adds them automatically).






          share|improve this answer















          Found a solution.



          For API 23 and higher add to your TextView:



          android:breakStrategy="simple"


          For API < 23 remove hidden &nbsp; from you text dynamically (android adds them automatically).







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Nov 14 '18 at 0:44









          André Sousa

          1,1581818




          1,1581818










          answered Nov 14 '18 at 0:22









          JbwzJbwz

          4010




          4010























              0














              code is correct give the space between the words



              not : "jhjhhjhjhhjhddfhdjfdfdfgdjdjfdj"



              try : Hey mate,how youre doing how are youre doing how youre doing how youre doing ?



              android:layout_width="match_parent" // if needed






              share|improve this answer






























                0














                code is correct give the space between the words



                not : "jhjhhjhjhhjhddfhdjfdfdfgdjdjfdj"



                try : Hey mate,how youre doing how are youre doing how youre doing how youre doing ?



                android:layout_width="match_parent" // if needed






                share|improve this answer




























                  0












                  0








                  0







                  code is correct give the space between the words



                  not : "jhjhhjhjhhjhddfhdjfdfdfgdjdjfdj"



                  try : Hey mate,how youre doing how are youre doing how youre doing how youre doing ?



                  android:layout_width="match_parent" // if needed






                  share|improve this answer















                  code is correct give the space between the words



                  not : "jhjhhjhjhhjhddfhdjfdfdfgdjdjfdj"



                  try : Hey mate,how youre doing how are youre doing how youre doing how youre doing ?



                  android:layout_width="match_parent" // if needed







                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited Nov 14 '18 at 6:58

























                  answered Nov 14 '18 at 6:47









                  veerendranveerendran

                  364




                  364






























                      draft saved

                      draft discarded




















































                      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.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function () {
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53291074%2fhow-to-force-textview-to-use-as-much-space-as-possible-on-the-first-line%23new-answer', 'question_page');
                      }
                      );

                      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







                      Popular posts from this blog

                      Florida Star v. B. J. F.

                      Danny Elfman

                      Retrieve a Users Dashboard in Tumblr with R and TumblR. Oauth Issues