【问题标题】:Width of textView increasing as text is added—androidtextView 的宽度随着文本的添加而增加—android
【发布时间】:2017-03-20 18:40:25
【问题描述】:

我在 android xml 中有一个 <textView>。然而,当我向这个 textview 添加文本时,它的宽度会增加。我希望它的宽度保持不变,正好是屏幕宽度的一半。我该怎么做?

<TextView
    android:id="@+id/decrypted"
    android:layout_height="100dp"
    android:layout_weight="0.5"
    android:background="@drawable/back"
    android:text=""/> <!--I want this to change without the entire width changing.-->

【问题讨论】:

  • 添加 android:layout_width="0dp"
  • 这似乎奏效了!谢谢。

标签: android xml textview


【解决方案1】:

试试这个:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal"
    android:weightSum="2">

    <TextView
        android:id="@+id/decrypted"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:background="@android:color/darker_gray"
        android:text="LONG TEXT LONG TEXT LONG TEXT LONG TEXTLONG TEXT LONG TEXT LONG TEXT"
        android:textColor="@android:color/black" />


</LinearLayout>

输出:

【讨论】:

  • 太棒了!我需要做的就是添加 android:layout_width="0dp"。这很好用!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-10-08
  • 2019-04-14
  • 2011-05-02
  • 2019-02-18
  • 1970-01-01
相关资源
最近更新 更多