У меня есть макет, и я хочу, чтобы все его компоненты соответствовали любому возможному разрешению экрана, но это не так. Выглядит, как и ожидалось, на пикселе 2.
layout.xml
, каждая константа определена в dp
:
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/gradient_background"
android:gravity="center"
android:orientation="vertical">
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/first_name_layout"
style="@style/MaterialTextInputLayout"
android:layout_width="@dimen/text_field_width"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/margin_default"
android:hint="@string/sign_up_first_name">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/first_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/transparent"
android:inputType="textPersonName" />
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/last_name_layout"
style="@style/MaterialTextInputLayout"
android:layout_width="@dimen/text_field_width"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/margin_default"
android:hint="@string/sign_up_last_name">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/last_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/transparent"
android:inputType="textPersonName" />
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/preferred_name_layout"
style="@style/MaterialTextInputLayout"
android:layout_width="@dimen/text_field_width"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/margin_default"
android:hint="@string/sign_up_pref_name">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/preferred_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/transparent"
android:inputType="textPersonName" />
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/phone_number_layout"
style="@style/MaterialTextInputLayout"
android:layout_width="@dimen/text_field_width"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/margin_default"
android:hint="@string/sign_up_phone_number">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/phone_number"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/transparent"
android:inputType="phone" />
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/email_layout"
style="@style/MaterialTextInputLayout"
android:layout_width="@dimen/text_field_width"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/margin_default"
android:hint="@string/sign_up_email">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/email"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/transparent"
android:inputType="textEmailAddress" />
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/password_layout"
style="@style/MaterialTextInputLayout"
android:layout_width="@dimen/text_field_width"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/margin_default"
android:hint="@string/sign_up_password"
app:endIconMode="password_toggle">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/transparent"
android:inputType="textPassword" />
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/password_confirmation_layout"
style="@style/MaterialTextInputLayout"
android:layout_width="@dimen/text_field_width"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/margin_default"
android:hint="@string/sign_up_password_confirmation"
app:endIconMode="password_toggle">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/password_confirmation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/transparent"
android:inputType="textPassword" />
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.button.MaterialButton
android:id="@+id/submit_btn"
android:layout_width="@dimen/default_button_width"
android:layout_height="@dimen/default_button_height"
android:layout_marginTop="@dimen/margin_big"
android:elevation="2dp"
android:text="@string/wizard_sign_up_submit"
android:textColor="@color/white" />
</LinearLayout>
</layout>
Слева направо: