NLam
NLam

Reputation: 557

Tops of text cutoff in EditText

I have an EditText in a RelativeLayout where the tops of the text in the EditText are getting cutoff. I have tried increasing the padding for the EditText, but even at 20dp, the text still gets clipped.

I tried to post an image here, but apparently I don't have enough of a reputation for stackoverflow to allow me to post one. Imagine a lined paper with a dotted line horizontally in the middle like you had in grade school. The text gets clipped for anything above the dotted line.

Here is my layout.xml:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
          android:layout_width="fill_parent"
          android:layout_height="fill_parent"
          android:orientation="vertical">
<RelativeLayout android:layout_width="fill_parent"
                android:layout_height="wrap_content">
    <TextView android:id="@+id/questionTextView"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:layout_marginTop="0dp"
              android:layout_marginLeft="10dp"
              android:textSize="16dp"
              android:text="Audit Question"/>
    <RadioButton android:id="@+id/answerRadioButton"
                 android:layout_width="wrap_content"
                 android:layout_height="wrap_content"
                 android:layout_below="@id/questionTextView"
                 android:layout_alignLeft="@id/questionTextView"
                 android:layout_marginTop="5dp"
                 android:checked="true"
                 android:textSize="16dp"
                 android:text="audit answer"/>
    <EditText android:id="@+id/commentEditText"
              android:layout_width="fill_parent"
              android:layout_height="wrap_content"
              android:layout_below="@id/answerRadioButton"
              android:layout_marginLeft="20dp"
              android:layout_marginRight="20dp"
              android:layout_marginBottom="10dp"
              android:padding="20dp" />
</RelativeLayout>

Any help would be greatly appreciated.

Upvotes: 2

Views: 5992

Answers (3)

Dave Hubbard
Dave Hubbard

Reputation: 499

I found this when I switched a vertical LinearLayout of 4 sub horizontal Layouts to being equally distributed. I then found that EditText seems to have non-zero padding and margins at the bottom (at least) which seemed to mess up Android's spacing. Here is one of my 4 horizontal views that worked. Annoying.

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="1"
    android:layout_margin="8dp"
    android:orientation="horizontal">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_vertical"
        android:text="@string/type_label"/>

    <EditText
        android:id="@+id/division_type"
        android:inputType="textNoSuggestions|textCapSentences"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:paddingBottom="5dp"
        android:layout_marginBottom="-4dp"
        android:hint="@string/divison_type_hint"/>

</LinearLayout>

Upvotes: 0

NLam
NLam

Reputation: 557

I am unclear as to why this worked, but when I added a TextView buffer at the bottom below the EditText widget, the text was no longer cutoff.

I added this:

    <TextView android:layout_width="fill_parent"
          android:layout_height="5dp" />

And the text within the EditText now looks as it should.

Upvotes: 0

jmhend
jmhend

Reputation: 537

Difference between a View's Padding and Margin

Padding will add space been the content of your EditText view and the border constaints of itself, meaning it might be the problem as to why your EditText is being clipped-- it's contraining itself. Try to add android:layout_marginTop to your EditText instead, to create space between it and the RadioButton.

Upvotes: 2

Related Questions