添加文本时textView的宽度增加 - android

时间:2017-03-20 18:40:25

标签: android xml textview

我在android xml中有一个<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.-->

1 个答案:

答案 0 :(得分: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>

输出:

enter image description here

相关问题