Q:

Width of textView increasing as text is added—android

I have a <textView> in android xml. When I add text to this textview, however, its width increases. I want its width to remain constant at exactly half the screen's width. How can I do this?
<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.-->

A:

Try this:
<?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>

output:

