文本视图内容更改后宽度不会自适应

4

我正在尝试使用EditText输入的数据更新TextView的内容。但是,如果原始文本(提示)比新文本大,则宽度不会改变。

我在TextView的Hint属性中有以下字符串:“请介绍一个金额”。例如,如果我输入25'5,则TextView不会调整其宽度。

第一屏幕 First Screen

第二屏幕 Second Screen

欧元符号位于TextView后面不可见,在插入某些值后显示。

金额代码片段:

<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>

展示你的 .xml 文件。 - user3793589
1
我猜你的问题根源在于tvEuroSymbol中的android:layout_width="match_parent"。尝试将其更改为wrap_content或设置**gravity="left"**。 - temnoi
@temnoi,很遗憾,那些更改对我不起作用。 tvImporteDesc 的宽度保持足够宽以容纳其原始文本,导致问题。 - bradkratky
1个回答

1

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接