【问题标题】:Textview width doens't adjust after change content更改内容后Textview宽度不调整
【发布时间】:2016-11-06 07:58:48
【问题描述】:

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

我在 TextView 的提示属性中有下一个字符串,“请介绍一个数量”。例如,如果我输入 25'5,则 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 文件
  • 我想你的问题根源在 tvEuroSymbol 的android:layout_width="match_parent"。尝试将其更改为 wrap_content 或设置 gravity="left"
  • @temnoi 不幸的是,这些更改对我不起作用。 tvImporteDesc 的宽度对其原始文本保持足够的固定宽度,从而导致问题

标签: android textview width


【解决方案1】:

您似乎想动态更改 tvImporteDesc 的宽度。简而言之,Android 不允许这样做,尽管有些人已经开发了变通方法。 (切换某些答案建议的可见性对我不起作用)。类似的问题:

Change Relative layout width and height dynamically

WRAP_CONTENT not working after dynamically adding views

由于您试图将文本放在同一行上,因此为该行文本使用单个 TextView 并连接欧元符号可能更容易?

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-01-24
    • 1970-01-01
    • 2011-03-22
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多