smeeb
smeeb

Reputation: 29477

Adding padding or buffers to Android XML views

I have the following Android Activity:

enter image description here

As you can see, the EditText views need to come down just a few pixels lower so that the entire text can be displayed (without being cut off). Here is my XML for this activity:

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.example.myuser.myapp.O1LoginActivity">

    <TextView
        android:id="@+id/textView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Opponent 1 Login"
        android:textSize="18sp"
        tools:layout_editor_absoluteY="1dp"
        android:layout_marginLeft="16dp"
        layout_constraintLeft_toLeftOf="parent"
        layout_constraintTop_toTopOf="parent" />

    <TextView
        android:id="@+id/textView6"
        android:layout_width="55dp"
        android:layout_height="17dp"
        android:layout_marginLeft="16dp"
        android:text="Username:"
        android:textSize="14sp"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/textView2" />

    <EditText
        android:id="@+id/o1.username"
        android:layout_width="219dp"
        android:layout_height="31dp"
        android:ems="10"
        android:inputType="textPersonName"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/textView6" />

    <TextView
        android:id="@+id/textView10"
        android:layout_width="55dp"
        android:layout_height="17dp"
        android:layout_marginLeft="16dp"
        android:text="Password:"
        android:textSize="14sp"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/o1.username" />

    <EditText
        android:id="@+id/o1.password"
        android:layout_width="219dp"
        android:layout_height="31dp"
        android:ems="10"
        android:inputType="textPersonName"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/textView10" />

    <Button
        android:id="@+id/button3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="7dp"
        android:onClick="toO2Login"
        android:text="Next >>"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent" />

</android.support.constraint.ConstraintLayout>

I'd really prefer to keep the existing constraints (layout_constraintLeft_toLeftOf, layout_constraintTop_toBottomOf, etc.) in place, because I want each subsequent view to appear left-aligned and beneath the previous view/widget. I'm just looking to add a buffer/margin to the top of my EditText instances so that the text (when entered in) doesn't get truncated. Any ideas?

Upvotes: 0

Views: 202

Answers (1)

Haresh Chaudhary
Haresh Chaudhary

Reputation: 4400

As mentioned in the comment below your question by @Mohamed_AbdAllah, the height you have given for the views is too less than the text size. Change it to wrap_content as below and it should be good.

<TextView
    android:id="@+id/textView6"
    android:layout_width="55dp"
    android:layout_height="wrap_content"
    android:layout_marginLeft="16dp"
    android:text="Username:"
    android:textSize="14sp"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/textView2" />

<EditText
    android:id="@+id/o1.username"
    android:layout_width="219dp"
    android:layout_height="wrap_content"
    android:ems="10"
    android:inputType="textPersonName"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/textView6" />

Upvotes: 3

Related Questions