4

I'm trying to update the content of a TextView with the data introduced by an EditText. But after change the text, if the original text (hint) was bigger than the new text, the width doens't change.

I have the next string in the Hint Attribute of the TextView, "Please, introduce a amount". If I put 25'5, for example, the textview doesn't resize it width.

First Screen First Screen

Second Screen Second Screen

The Euro symbol is invisible behind the textview, and It's shown after insert some value.

The piece of code for the Amount:

<RelativeLayout
                android:id="@+id/rlImporte"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="@drawable/rel_layout_colors"
                android:clickable="true"
                android:paddingTop="8dp"
                android:paddingBottom="8dp">

                <ImageView
                    android:id="@+id/lst_img3"
                    android:layout_width="50dp"
                    android:layout_height="50dp"
                    android:layout_alignParentLeft="true"
                    android:layout_alignParentTop="true"
                    android:layout_margin="5sp"
                    android:layout_marginTop="5dp"
                    android:src="@drawable/icon_importe"/>

                <TextView
                    android:id="@+id/tvImporte"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_alignParentTop="false"
                    android:layout_marginTop="5dp"
                    android:layout_toRightOf="@+id/lst_img3"
                    android:text="@string/IMPORTE_TITLE_STRING"
                    android:textColor="@android:color/black"
                    android:textSize="@dimen/title_text_size" />

                <TextView
                    android:id="@+id/tvImporteDesc"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_below="@+id/tvImporte"
                    android:layout_toRightOf="@+id/lst_img3"
                    android:textColor="@android:color/darker_gray"
                    android:textSize="@dimen/subtitle_text_size"
                    android:visibility="visible"
                    android:hint="@string/IMPORTE_PLACEHOLDER_STRING"
                    android:textColorHint="@android:color/darker_gray"
                    android:ellipsize="start"
                    android:layout_marginRight="4dp" />

                <TextView
                    android:id="@+id/tvEuroSymbol"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_below="@+id/tvImporte"
                    android:layout_toRightOf="@+id/tvImporteDesc"
                    android:textColor="@android:color/darker_gray"
                    android:textSize="@dimen/subtitle_text_size"
                    android:visibility="gone"
                    android:hint="@string/euro_symbol"
                    android:textColorHint="@color/blue_quantion"
                    android:ellipsize="start"
                    android:paddingLeft="4dp" />

            </RelativeLayout>
Víctor Martín
  • 3,352
  • 7
  • 48
  • 94
  • Show your .xml file – user3793589 Jul 04 '16 at 14:36
  • 1
    I suppose the root of your problem in `android:layout_width="match_parent"` at the tvEuroSymbol. Try to change it to **wrap_content** or set **gravity="left"** – vchornenyi Jul 04 '16 at 14:55
  • @temnoi those changes don't work for me, unfortunately. The width of tvImporteDesc stays fixed wide enough for it's original text, causing the problem – bradkratky Jul 04 '16 at 15:23

1 Answers1

1

You seem like you want to change the width of tvImporteDesc dynamically. The short of it is that Android does not allow this, though some people have developed work arounds. (Toggling the visibility that some answers suggest did not work for me). Similar questions:

Change Relative layout width and height dynamically

WRAP_CONTENT not working after dynamically adding views

Since you are trying to fit text on the same line it might be easier to use a single TextView for that line of text, and concatenate the euro symbol?

Community
  • 1
  • 1
bradkratky
  • 1,577
  • 1
  • 14
  • 28