TextView text wrap and width












0















The idea is to have TextView and ImageButton to the right of it. TextView is multiline, both are centered verically (depends on who is higher). All goes well until some long texts are moved to the next line, leaving huge hole between (visible) right edge of TextView. It works good, but looks not. How can you suggest to do this?



Too make it more clear: the button should be to the right visible edge of TextView, not to the right of parent. The problem is to understand TextView's visible width, I mean the width of it's content.



enter image description here



<?xml version="1.0" encoding="utf-8"?>
<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">

<TextView
android:id="@+id/title"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:fontFamily="@font/proxima_nova_regular"
android:textSize="14sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:text="Some title"/>

<RelativeLayout
android:id="@+id/holder"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/title">

<TextView
android:id="@+id/name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="false"
android:layout_centerVertical="true"
android:fontFamily="@font/proxima_nova_regular"
android:paddingEnd="40dp"
android:textSize="20sp"
tools:text="aaaaaaaa bbbbb ddddddddddddddddd eeee"/>

<ImageButton
android:id="@+id/btn"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_centerVertical="true"
android:layout_marginStart="-40dp"
android:layout_toEndOf="@id/name"
android:clickable="true"
android:contentDescription="@string/standard_content_description"
android:focusable="true"
android:padding="4dp"
app:srcCompat="@android:drawable/btn_star_big_on"/>
</RelativeLayout>

</android.support.constraint.ConstraintLayout>









share|improve this question





























    0















    The idea is to have TextView and ImageButton to the right of it. TextView is multiline, both are centered verically (depends on who is higher). All goes well until some long texts are moved to the next line, leaving huge hole between (visible) right edge of TextView. It works good, but looks not. How can you suggest to do this?



    Too make it more clear: the button should be to the right visible edge of TextView, not to the right of parent. The problem is to understand TextView's visible width, I mean the width of it's content.



    enter image description here



    <?xml version="1.0" encoding="utf-8"?>
    <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">

    <TextView
    android:id="@+id/title"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:fontFamily="@font/proxima_nova_regular"
    android:textSize="14sp"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent"
    tools:text="Some title"/>

    <RelativeLayout
    android:id="@+id/holder"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/title">

    <TextView
    android:id="@+id/name"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerHorizontal="false"
    android:layout_centerVertical="true"
    android:fontFamily="@font/proxima_nova_regular"
    android:paddingEnd="40dp"
    android:textSize="20sp"
    tools:text="aaaaaaaa bbbbb ddddddddddddddddd eeee"/>

    <ImageButton
    android:id="@+id/btn"
    android:layout_width="40dp"
    android:layout_height="40dp"
    android:layout_centerVertical="true"
    android:layout_marginStart="-40dp"
    android:layout_toEndOf="@id/name"
    android:clickable="true"
    android:contentDescription="@string/standard_content_description"
    android:focusable="true"
    android:padding="4dp"
    app:srcCompat="@android:drawable/btn_star_big_on"/>
    </RelativeLayout>

    </android.support.constraint.ConstraintLayout>









    share|improve this question



























      0












      0








      0








      The idea is to have TextView and ImageButton to the right of it. TextView is multiline, both are centered verically (depends on who is higher). All goes well until some long texts are moved to the next line, leaving huge hole between (visible) right edge of TextView. It works good, but looks not. How can you suggest to do this?



      Too make it more clear: the button should be to the right visible edge of TextView, not to the right of parent. The problem is to understand TextView's visible width, I mean the width of it's content.



      enter image description here



      <?xml version="1.0" encoding="utf-8"?>
      <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">

      <TextView
      android:id="@+id/title"
      android:layout_width="0dp"
      android:layout_height="wrap_content"
      android:fontFamily="@font/proxima_nova_regular"
      android:textSize="14sp"
      app:layout_constraintEnd_toEndOf="parent"
      app:layout_constraintStart_toStartOf="parent"
      app:layout_constraintTop_toTopOf="parent"
      tools:text="Some title"/>

      <RelativeLayout
      android:id="@+id/holder"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      app:layout_constraintEnd_toEndOf="parent"
      app:layout_constraintStart_toStartOf="parent"
      app:layout_constraintTop_toBottomOf="@+id/title">

      <TextView
      android:id="@+id/name"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_centerHorizontal="false"
      android:layout_centerVertical="true"
      android:fontFamily="@font/proxima_nova_regular"
      android:paddingEnd="40dp"
      android:textSize="20sp"
      tools:text="aaaaaaaa bbbbb ddddddddddddddddd eeee"/>

      <ImageButton
      android:id="@+id/btn"
      android:layout_width="40dp"
      android:layout_height="40dp"
      android:layout_centerVertical="true"
      android:layout_marginStart="-40dp"
      android:layout_toEndOf="@id/name"
      android:clickable="true"
      android:contentDescription="@string/standard_content_description"
      android:focusable="true"
      android:padding="4dp"
      app:srcCompat="@android:drawable/btn_star_big_on"/>
      </RelativeLayout>

      </android.support.constraint.ConstraintLayout>









      share|improve this question
















      The idea is to have TextView and ImageButton to the right of it. TextView is multiline, both are centered verically (depends on who is higher). All goes well until some long texts are moved to the next line, leaving huge hole between (visible) right edge of TextView. It works good, but looks not. How can you suggest to do this?



      Too make it more clear: the button should be to the right visible edge of TextView, not to the right of parent. The problem is to understand TextView's visible width, I mean the width of it's content.



      enter image description here



      <?xml version="1.0" encoding="utf-8"?>
      <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">

      <TextView
      android:id="@+id/title"
      android:layout_width="0dp"
      android:layout_height="wrap_content"
      android:fontFamily="@font/proxima_nova_regular"
      android:textSize="14sp"
      app:layout_constraintEnd_toEndOf="parent"
      app:layout_constraintStart_toStartOf="parent"
      app:layout_constraintTop_toTopOf="parent"
      tools:text="Some title"/>

      <RelativeLayout
      android:id="@+id/holder"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      app:layout_constraintEnd_toEndOf="parent"
      app:layout_constraintStart_toStartOf="parent"
      app:layout_constraintTop_toBottomOf="@+id/title">

      <TextView
      android:id="@+id/name"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_centerHorizontal="false"
      android:layout_centerVertical="true"
      android:fontFamily="@font/proxima_nova_regular"
      android:paddingEnd="40dp"
      android:textSize="20sp"
      tools:text="aaaaaaaa bbbbb ddddddddddddddddd eeee"/>

      <ImageButton
      android:id="@+id/btn"
      android:layout_width="40dp"
      android:layout_height="40dp"
      android:layout_centerVertical="true"
      android:layout_marginStart="-40dp"
      android:layout_toEndOf="@id/name"
      android:clickable="true"
      android:contentDescription="@string/standard_content_description"
      android:focusable="true"
      android:padding="4dp"
      app:srcCompat="@android:drawable/btn_star_big_on"/>
      </RelativeLayout>

      </android.support.constraint.ConstraintLayout>






      android android-textview






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 14 '18 at 13:38







      Alex Shiganov

















      asked Nov 13 '18 at 19:41









      Alex ShiganovAlex Shiganov

      489




      489
























          4 Answers
          4






          active

          oldest

          votes


















          0














          add android:layout_alignParentRight="true"



              <ImageButton
          android:layout_alignParentRight="true"
          android:id="@+id/btn"
          android:layout_width="40dp"
          android:layout_height="40dp"
          android:layout_centerVertical="true"
          android:layout_toEndOf="@id/name"
          android:clickable="true"
          android:contentDescription="@string/standard_content_description"
          android:focusable="true"
          android:padding="4dp"
          app:srcCompat="@android:drawable/btn_star_big_on"/>





          share|improve this answer
























          • No, the button should be to the right visible edge of TextView, not to the right of parent.

            – Alex Shiganov
            Nov 14 '18 at 13:38



















          0














          You need to fix the image at the end of screen to make it more stable UI. Otherwise it's look odd due to different positions of Image. To do so add these to your code:



          add android:layout_alignParentRight="true"



          and romove android:layout_toEndOf="@id/name"






          share|improve this answer
























          • No, the button should be to the right visible edge of TextView, not to the right of parent.

            – Alex Shiganov
            Nov 14 '18 at 13:44



















          0














          First, do as others have suggested and set attribute for the ImageButton
          android:layout_alignParentEnd="true"



          Second, get rid of the padding end on the textView. All that is doing for you is killing the amount of space available for text.



          Third, add an attribute to your TextView to align to start of the image.
          android:layout_toStartOf="@+id/btn"



          Your code should look something like this:



             <TextView
          android:id="@+id/name"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_centerHorizontal="false"
          android:layout_centerVertical="true"
          android:fontFamily="sans-serif"
          android:textSize="20sp"
          android:layout_toStartOf="@+id/btn"
          tools:text="aaaaaaaa bbbbb dddddddd haveeverythinginlinefortheotherpeopletoseewhatyouhavedoneinthemaintextview"/>

          <ImageButton
          android:id="@+id/btn"
          android:layout_width="40dp"
          android:layout_height="40dp"
          android:layout_centerVertical="true"
          android:layout_alignParentEnd="true"
          android:clickable="true"
          android:focusable="true"
          android:padding="4dp"
          app:srcCompat="@android:drawable/btn_star_big_on"/>


          enter image description hereNow you can have the text wrap that you want. However, Android TextView does not have an attribute that allows for hyphens and cannot decide where to break a long word or set of letters. Therefore, the textView will break when it is convenient for it to do so, like after a space in the text. Otherwise, it will allow text to fill the container until the end of a line and continue on the next line.






          share|improve this answer
























          • The button should be to the right visible edge of TextView, not to the right of parent. The problem is to understand TextView's visible width, I mean the width of it's content.

            – Alex Shiganov
            Nov 14 '18 at 13:45











          • With the changes I suggested, the button will stay to the right side of the layout and not move as the wrap_content of the text gets bigger or smaller. As I mentioned before "TextView does not have an attribute that allows for hyphens and cannot decide where to break a long word or set of letters. Therefore, the textView will break when it is convenient for it to do so". You cannot control the "text wrap" like you can in MS Word. Of course you can still align the button to the textView and it will move based on how much text is available.

            – EPAgg
            Nov 16 '18 at 6:19





















          -1














          Please add code like below.
          <RelativeLayout
          android:layout_width="match_parent"
          android:layout_height="wrap_content">
          <TextView
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:id="@+id/from1"
          android:maxLength="8"
          android:maxLines="1"
          android:paddingTop="8dp"
          android:hint="55"
          android:paddingStart="10dp"
          android:background="@drawable/textlayout"
          android:layout_alignParentStart="true"/>
          <ImageButton
          android:layout_width="wrap_content"
          android:layout_toRightOf="@+id/from1"
          android:gravity="center"
          app:srcCompat="@android:drawable/start_btn"
          android:layout_height="35dp" />
          </RelativeLayout>





          share|improve this answer
























          • The button should be to the right visible edge of TextView, not to the right of parent. TextView should support multiline.

            – Alex Shiganov
            Nov 14 '18 at 13:44











          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%2f53288363%2ftextview-text-wrap-and-width%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          4 Answers
          4






          active

          oldest

          votes








          4 Answers
          4






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          0














          add android:layout_alignParentRight="true"



              <ImageButton
          android:layout_alignParentRight="true"
          android:id="@+id/btn"
          android:layout_width="40dp"
          android:layout_height="40dp"
          android:layout_centerVertical="true"
          android:layout_toEndOf="@id/name"
          android:clickable="true"
          android:contentDescription="@string/standard_content_description"
          android:focusable="true"
          android:padding="4dp"
          app:srcCompat="@android:drawable/btn_star_big_on"/>





          share|improve this answer
























          • No, the button should be to the right visible edge of TextView, not to the right of parent.

            – Alex Shiganov
            Nov 14 '18 at 13:38
















          0














          add android:layout_alignParentRight="true"



              <ImageButton
          android:layout_alignParentRight="true"
          android:id="@+id/btn"
          android:layout_width="40dp"
          android:layout_height="40dp"
          android:layout_centerVertical="true"
          android:layout_toEndOf="@id/name"
          android:clickable="true"
          android:contentDescription="@string/standard_content_description"
          android:focusable="true"
          android:padding="4dp"
          app:srcCompat="@android:drawable/btn_star_big_on"/>





          share|improve this answer
























          • No, the button should be to the right visible edge of TextView, not to the right of parent.

            – Alex Shiganov
            Nov 14 '18 at 13:38














          0












          0








          0







          add android:layout_alignParentRight="true"



              <ImageButton
          android:layout_alignParentRight="true"
          android:id="@+id/btn"
          android:layout_width="40dp"
          android:layout_height="40dp"
          android:layout_centerVertical="true"
          android:layout_toEndOf="@id/name"
          android:clickable="true"
          android:contentDescription="@string/standard_content_description"
          android:focusable="true"
          android:padding="4dp"
          app:srcCompat="@android:drawable/btn_star_big_on"/>





          share|improve this answer













          add android:layout_alignParentRight="true"



              <ImageButton
          android:layout_alignParentRight="true"
          android:id="@+id/btn"
          android:layout_width="40dp"
          android:layout_height="40dp"
          android:layout_centerVertical="true"
          android:layout_toEndOf="@id/name"
          android:clickable="true"
          android:contentDescription="@string/standard_content_description"
          android:focusable="true"
          android:padding="4dp"
          app:srcCompat="@android:drawable/btn_star_big_on"/>






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 13 '18 at 19:46









          Sari MasriSari Masri

          1297




          1297













          • No, the button should be to the right visible edge of TextView, not to the right of parent.

            – Alex Shiganov
            Nov 14 '18 at 13:38



















          • No, the button should be to the right visible edge of TextView, not to the right of parent.

            – Alex Shiganov
            Nov 14 '18 at 13:38

















          No, the button should be to the right visible edge of TextView, not to the right of parent.

          – Alex Shiganov
          Nov 14 '18 at 13:38





          No, the button should be to the right visible edge of TextView, not to the right of parent.

          – Alex Shiganov
          Nov 14 '18 at 13:38













          0














          You need to fix the image at the end of screen to make it more stable UI. Otherwise it's look odd due to different positions of Image. To do so add these to your code:



          add android:layout_alignParentRight="true"



          and romove android:layout_toEndOf="@id/name"






          share|improve this answer
























          • No, the button should be to the right visible edge of TextView, not to the right of parent.

            – Alex Shiganov
            Nov 14 '18 at 13:44
















          0














          You need to fix the image at the end of screen to make it more stable UI. Otherwise it's look odd due to different positions of Image. To do so add these to your code:



          add android:layout_alignParentRight="true"



          and romove android:layout_toEndOf="@id/name"






          share|improve this answer
























          • No, the button should be to the right visible edge of TextView, not to the right of parent.

            – Alex Shiganov
            Nov 14 '18 at 13:44














          0












          0








          0







          You need to fix the image at the end of screen to make it more stable UI. Otherwise it's look odd due to different positions of Image. To do so add these to your code:



          add android:layout_alignParentRight="true"



          and romove android:layout_toEndOf="@id/name"






          share|improve this answer













          You need to fix the image at the end of screen to make it more stable UI. Otherwise it's look odd due to different positions of Image. To do so add these to your code:



          add android:layout_alignParentRight="true"



          and romove android:layout_toEndOf="@id/name"







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 13 '18 at 19:52









          Sultan MahmudSultan Mahmud

          23017




          23017













          • No, the button should be to the right visible edge of TextView, not to the right of parent.

            – Alex Shiganov
            Nov 14 '18 at 13:44



















          • No, the button should be to the right visible edge of TextView, not to the right of parent.

            – Alex Shiganov
            Nov 14 '18 at 13:44

















          No, the button should be to the right visible edge of TextView, not to the right of parent.

          – Alex Shiganov
          Nov 14 '18 at 13:44





          No, the button should be to the right visible edge of TextView, not to the right of parent.

          – Alex Shiganov
          Nov 14 '18 at 13:44











          0














          First, do as others have suggested and set attribute for the ImageButton
          android:layout_alignParentEnd="true"



          Second, get rid of the padding end on the textView. All that is doing for you is killing the amount of space available for text.



          Third, add an attribute to your TextView to align to start of the image.
          android:layout_toStartOf="@+id/btn"



          Your code should look something like this:



             <TextView
          android:id="@+id/name"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_centerHorizontal="false"
          android:layout_centerVertical="true"
          android:fontFamily="sans-serif"
          android:textSize="20sp"
          android:layout_toStartOf="@+id/btn"
          tools:text="aaaaaaaa bbbbb dddddddd haveeverythinginlinefortheotherpeopletoseewhatyouhavedoneinthemaintextview"/>

          <ImageButton
          android:id="@+id/btn"
          android:layout_width="40dp"
          android:layout_height="40dp"
          android:layout_centerVertical="true"
          android:layout_alignParentEnd="true"
          android:clickable="true"
          android:focusable="true"
          android:padding="4dp"
          app:srcCompat="@android:drawable/btn_star_big_on"/>


          enter image description hereNow you can have the text wrap that you want. However, Android TextView does not have an attribute that allows for hyphens and cannot decide where to break a long word or set of letters. Therefore, the textView will break when it is convenient for it to do so, like after a space in the text. Otherwise, it will allow text to fill the container until the end of a line and continue on the next line.






          share|improve this answer
























          • The button should be to the right visible edge of TextView, not to the right of parent. The problem is to understand TextView's visible width, I mean the width of it's content.

            – Alex Shiganov
            Nov 14 '18 at 13:45











          • With the changes I suggested, the button will stay to the right side of the layout and not move as the wrap_content of the text gets bigger or smaller. As I mentioned before "TextView does not have an attribute that allows for hyphens and cannot decide where to break a long word or set of letters. Therefore, the textView will break when it is convenient for it to do so". You cannot control the "text wrap" like you can in MS Word. Of course you can still align the button to the textView and it will move based on how much text is available.

            – EPAgg
            Nov 16 '18 at 6:19


















          0














          First, do as others have suggested and set attribute for the ImageButton
          android:layout_alignParentEnd="true"



          Second, get rid of the padding end on the textView. All that is doing for you is killing the amount of space available for text.



          Third, add an attribute to your TextView to align to start of the image.
          android:layout_toStartOf="@+id/btn"



          Your code should look something like this:



             <TextView
          android:id="@+id/name"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_centerHorizontal="false"
          android:layout_centerVertical="true"
          android:fontFamily="sans-serif"
          android:textSize="20sp"
          android:layout_toStartOf="@+id/btn"
          tools:text="aaaaaaaa bbbbb dddddddd haveeverythinginlinefortheotherpeopletoseewhatyouhavedoneinthemaintextview"/>

          <ImageButton
          android:id="@+id/btn"
          android:layout_width="40dp"
          android:layout_height="40dp"
          android:layout_centerVertical="true"
          android:layout_alignParentEnd="true"
          android:clickable="true"
          android:focusable="true"
          android:padding="4dp"
          app:srcCompat="@android:drawable/btn_star_big_on"/>


          enter image description hereNow you can have the text wrap that you want. However, Android TextView does not have an attribute that allows for hyphens and cannot decide where to break a long word or set of letters. Therefore, the textView will break when it is convenient for it to do so, like after a space in the text. Otherwise, it will allow text to fill the container until the end of a line and continue on the next line.






          share|improve this answer
























          • The button should be to the right visible edge of TextView, not to the right of parent. The problem is to understand TextView's visible width, I mean the width of it's content.

            – Alex Shiganov
            Nov 14 '18 at 13:45











          • With the changes I suggested, the button will stay to the right side of the layout and not move as the wrap_content of the text gets bigger or smaller. As I mentioned before "TextView does not have an attribute that allows for hyphens and cannot decide where to break a long word or set of letters. Therefore, the textView will break when it is convenient for it to do so". You cannot control the "text wrap" like you can in MS Word. Of course you can still align the button to the textView and it will move based on how much text is available.

            – EPAgg
            Nov 16 '18 at 6:19
















          0












          0








          0







          First, do as others have suggested and set attribute for the ImageButton
          android:layout_alignParentEnd="true"



          Second, get rid of the padding end on the textView. All that is doing for you is killing the amount of space available for text.



          Third, add an attribute to your TextView to align to start of the image.
          android:layout_toStartOf="@+id/btn"



          Your code should look something like this:



             <TextView
          android:id="@+id/name"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_centerHorizontal="false"
          android:layout_centerVertical="true"
          android:fontFamily="sans-serif"
          android:textSize="20sp"
          android:layout_toStartOf="@+id/btn"
          tools:text="aaaaaaaa bbbbb dddddddd haveeverythinginlinefortheotherpeopletoseewhatyouhavedoneinthemaintextview"/>

          <ImageButton
          android:id="@+id/btn"
          android:layout_width="40dp"
          android:layout_height="40dp"
          android:layout_centerVertical="true"
          android:layout_alignParentEnd="true"
          android:clickable="true"
          android:focusable="true"
          android:padding="4dp"
          app:srcCompat="@android:drawable/btn_star_big_on"/>


          enter image description hereNow you can have the text wrap that you want. However, Android TextView does not have an attribute that allows for hyphens and cannot decide where to break a long word or set of letters. Therefore, the textView will break when it is convenient for it to do so, like after a space in the text. Otherwise, it will allow text to fill the container until the end of a line and continue on the next line.






          share|improve this answer













          First, do as others have suggested and set attribute for the ImageButton
          android:layout_alignParentEnd="true"



          Second, get rid of the padding end on the textView. All that is doing for you is killing the amount of space available for text.



          Third, add an attribute to your TextView to align to start of the image.
          android:layout_toStartOf="@+id/btn"



          Your code should look something like this:



             <TextView
          android:id="@+id/name"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_centerHorizontal="false"
          android:layout_centerVertical="true"
          android:fontFamily="sans-serif"
          android:textSize="20sp"
          android:layout_toStartOf="@+id/btn"
          tools:text="aaaaaaaa bbbbb dddddddd haveeverythinginlinefortheotherpeopletoseewhatyouhavedoneinthemaintextview"/>

          <ImageButton
          android:id="@+id/btn"
          android:layout_width="40dp"
          android:layout_height="40dp"
          android:layout_centerVertical="true"
          android:layout_alignParentEnd="true"
          android:clickable="true"
          android:focusable="true"
          android:padding="4dp"
          app:srcCompat="@android:drawable/btn_star_big_on"/>


          enter image description hereNow you can have the text wrap that you want. However, Android TextView does not have an attribute that allows for hyphens and cannot decide where to break a long word or set of letters. Therefore, the textView will break when it is convenient for it to do so, like after a space in the text. Otherwise, it will allow text to fill the container until the end of a line and continue on the next line.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 13 '18 at 21:03









          EPAggEPAgg

          188




          188













          • The button should be to the right visible edge of TextView, not to the right of parent. The problem is to understand TextView's visible width, I mean the width of it's content.

            – Alex Shiganov
            Nov 14 '18 at 13:45











          • With the changes I suggested, the button will stay to the right side of the layout and not move as the wrap_content of the text gets bigger or smaller. As I mentioned before "TextView does not have an attribute that allows for hyphens and cannot decide where to break a long word or set of letters. Therefore, the textView will break when it is convenient for it to do so". You cannot control the "text wrap" like you can in MS Word. Of course you can still align the button to the textView and it will move based on how much text is available.

            – EPAgg
            Nov 16 '18 at 6:19





















          • The button should be to the right visible edge of TextView, not to the right of parent. The problem is to understand TextView's visible width, I mean the width of it's content.

            – Alex Shiganov
            Nov 14 '18 at 13:45











          • With the changes I suggested, the button will stay to the right side of the layout and not move as the wrap_content of the text gets bigger or smaller. As I mentioned before "TextView does not have an attribute that allows for hyphens and cannot decide where to break a long word or set of letters. Therefore, the textView will break when it is convenient for it to do so". You cannot control the "text wrap" like you can in MS Word. Of course you can still align the button to the textView and it will move based on how much text is available.

            – EPAgg
            Nov 16 '18 at 6:19



















          The button should be to the right visible edge of TextView, not to the right of parent. The problem is to understand TextView's visible width, I mean the width of it's content.

          – Alex Shiganov
          Nov 14 '18 at 13:45





          The button should be to the right visible edge of TextView, not to the right of parent. The problem is to understand TextView's visible width, I mean the width of it's content.

          – Alex Shiganov
          Nov 14 '18 at 13:45













          With the changes I suggested, the button will stay to the right side of the layout and not move as the wrap_content of the text gets bigger or smaller. As I mentioned before "TextView does not have an attribute that allows for hyphens and cannot decide where to break a long word or set of letters. Therefore, the textView will break when it is convenient for it to do so". You cannot control the "text wrap" like you can in MS Word. Of course you can still align the button to the textView and it will move based on how much text is available.

          – EPAgg
          Nov 16 '18 at 6:19







          With the changes I suggested, the button will stay to the right side of the layout and not move as the wrap_content of the text gets bigger or smaller. As I mentioned before "TextView does not have an attribute that allows for hyphens and cannot decide where to break a long word or set of letters. Therefore, the textView will break when it is convenient for it to do so". You cannot control the "text wrap" like you can in MS Word. Of course you can still align the button to the textView and it will move based on how much text is available.

          – EPAgg
          Nov 16 '18 at 6:19













          -1














          Please add code like below.
          <RelativeLayout
          android:layout_width="match_parent"
          android:layout_height="wrap_content">
          <TextView
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:id="@+id/from1"
          android:maxLength="8"
          android:maxLines="1"
          android:paddingTop="8dp"
          android:hint="55"
          android:paddingStart="10dp"
          android:background="@drawable/textlayout"
          android:layout_alignParentStart="true"/>
          <ImageButton
          android:layout_width="wrap_content"
          android:layout_toRightOf="@+id/from1"
          android:gravity="center"
          app:srcCompat="@android:drawable/start_btn"
          android:layout_height="35dp" />
          </RelativeLayout>





          share|improve this answer
























          • The button should be to the right visible edge of TextView, not to the right of parent. TextView should support multiline.

            – Alex Shiganov
            Nov 14 '18 at 13:44
















          -1














          Please add code like below.
          <RelativeLayout
          android:layout_width="match_parent"
          android:layout_height="wrap_content">
          <TextView
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:id="@+id/from1"
          android:maxLength="8"
          android:maxLines="1"
          android:paddingTop="8dp"
          android:hint="55"
          android:paddingStart="10dp"
          android:background="@drawable/textlayout"
          android:layout_alignParentStart="true"/>
          <ImageButton
          android:layout_width="wrap_content"
          android:layout_toRightOf="@+id/from1"
          android:gravity="center"
          app:srcCompat="@android:drawable/start_btn"
          android:layout_height="35dp" />
          </RelativeLayout>





          share|improve this answer
























          • The button should be to the right visible edge of TextView, not to the right of parent. TextView should support multiline.

            – Alex Shiganov
            Nov 14 '18 at 13:44














          -1












          -1








          -1







          Please add code like below.
          <RelativeLayout
          android:layout_width="match_parent"
          android:layout_height="wrap_content">
          <TextView
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:id="@+id/from1"
          android:maxLength="8"
          android:maxLines="1"
          android:paddingTop="8dp"
          android:hint="55"
          android:paddingStart="10dp"
          android:background="@drawable/textlayout"
          android:layout_alignParentStart="true"/>
          <ImageButton
          android:layout_width="wrap_content"
          android:layout_toRightOf="@+id/from1"
          android:gravity="center"
          app:srcCompat="@android:drawable/start_btn"
          android:layout_height="35dp" />
          </RelativeLayout>





          share|improve this answer













          Please add code like below.
          <RelativeLayout
          android:layout_width="match_parent"
          android:layout_height="wrap_content">
          <TextView
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:id="@+id/from1"
          android:maxLength="8"
          android:maxLines="1"
          android:paddingTop="8dp"
          android:hint="55"
          android:paddingStart="10dp"
          android:background="@drawable/textlayout"
          android:layout_alignParentStart="true"/>
          <ImageButton
          android:layout_width="wrap_content"
          android:layout_toRightOf="@+id/from1"
          android:gravity="center"
          app:srcCompat="@android:drawable/start_btn"
          android:layout_height="35dp" />
          </RelativeLayout>






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 13 '18 at 20:06









          Vishal SharmaVishal Sharma

          1




          1













          • The button should be to the right visible edge of TextView, not to the right of parent. TextView should support multiline.

            – Alex Shiganov
            Nov 14 '18 at 13:44



















          • The button should be to the right visible edge of TextView, not to the right of parent. TextView should support multiline.

            – Alex Shiganov
            Nov 14 '18 at 13:44

















          The button should be to the right visible edge of TextView, not to the right of parent. TextView should support multiline.

          – Alex Shiganov
          Nov 14 '18 at 13:44





          The button should be to the right visible edge of TextView, not to the right of parent. TextView should support multiline.

          – Alex Shiganov
          Nov 14 '18 at 13:44


















          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%2f53288363%2ftextview-text-wrap-and-width%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

          Full-time equivalent

          さくらももこ

          13 indicted, 8 arrested in Calif. drug cartel investigation