Design a clean Android layout with XML
Build an accessible sign-in form with predictable spacing and readable labels.
What you’ll learn
Before you start
- An Android Views project
1. Choose a simple container
A vertical LinearLayout is suitable for a small form. Use match_parent for the available width and wrap_content where a view should size itself to its content.
2. Label the input
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:labelFor="@+id/email"
android:text="Email address" />
<EditText
android:id="@id/email"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textEmailAddress"
android:minHeight="48dp" />Put these views inside a root layout declaring the Android XML namespace. labelFor connects the visible label with the input. A hint alone is not a persistent visible label.
3. Test accessibility
Use sp for text and dp for spacing. Test with a larger system font, TalkBack, and the on-screen keyboard. Use a scroll container for forms that may exceed the available height.
Expected output
An email label sits above a full-width input. The input offers an email-oriented keyboard. This fragment provides layout only; it does not implement authentication.
Troubleshooting
If a view is missing, check its size and parent constraints. If text clips, remove fixed text-view heights and test larger font scales.