Quinn McHugh
Quinn McHugh

Reputation: 1707

EditText cuts off text

I’m working on my first app right now and have a slight XML problem. This is how my screen currently looks and as you can see the word “Invested” is cut in half.

android screenshot

Here is my code that is producing this behavior:

<LinearLayout 
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.quinnmchugh.networthcalculator.MainActivity$PlaceholderFragment" 
android:orientation="vertical" >

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal" >

    <TextView
        android:id="@+id/lblPrincipal"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:text="@string/principal"
        android:layout_weight="2"
        android:gravity="right"
        android:layout_marginRight="@dimen/activity_horizontal_margin"
        android:textSize="16sp" />

    <EditText
        android:id="@+id/txtPrincipal"
        android:layout_width="0dp"
        android:layout_height="wrap_content" 
        android:hint="ex. 5,000"
        android:layout_weight="3" />

</LinearLayout>

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal" >

    <TextView
        android:id="@+id/lblStartingSalary"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:text="@string/starting_salary"
        android:layout_weight="2"
        android:gravity="right"
        android:layout_marginRight="@dimen/activity_horizontal_margin"
        android:textSize="16sp" />

    <EditText
        android:id="@+id/txtStartingSalary"
        android:layout_width="0dp"
        android:layout_height="wrap_content" 
        android:hint="ex. 60,000"
        android:layout_weight="3" />

</LinearLayout>

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    android:layout_marginTop="24dp" >

    <TextView
        android:id="@+id/lblAnnualReturn"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:text="@string/annual_return"
        android:layout_weight="2"
        android:gravity="right"
        android:layout_marginRight="@dimen/activity_horizontal_margin"
        android:textSize="16sp" />

    <EditText
        android:id="@+id/txtAnnualReturn"
        android:layout_width="0dp"
        android:layout_height="wrap_content" 
        android:hint="ex. 7%"
        android:layout_weight="3" />

</LinearLayout>

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal" >

    <TextView
        android:id="@+id/lblPercentOfIncome"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:text="@string/percent_of_income"
        android:layout_weight="2"
        android:gravity="right"
        android:layout_marginRight="@dimen/activity_horizontal_margin"
        android:textSize="16sp" />

    <EditText
        android:id="@+id/txtPercentOfIncome"
        android:layout_width="0dp"
        android:layout_height="wrap_content" 
        android:hint="ex. 15%"
        android:layout_weight="3" />

</LinearLayout>

What do I need to fix to get the EditText to fully wrap itself and display the entire contents of the string?

Upvotes: 1

Views: 3583

Answers (2)

Prasanth Louis
Prasanth Louis

Reputation: 5056

Append a new line "\n" to your text. This will always show all of your text.

Upvotes: 0

Booger
Booger

Reputation: 18725

Add some padding to the element that is getting cut-off. Something like:

<TextView
    android:id="@+id/lblPercentOfIncome"
    ...
    android:paddingBottom="16dp" />

Upvotes: 1

Related Questions