Схема контрацепции Адаптировать для всех экранов - PullRequest
0 голосов
/ 25 октября 2018

Я учусь constraint макет.Я новичок в constraint макете.Я прочитал несколько уроков и получил хорошее представление о макете.Но когда я пытаюсь реализовать макет, я изо всех сил стараюсь соответствовать всем экранам.Здесь я прикрепил образец экрана.Я проектирую экран входа в систему.Я хочу приспособить этот дизайн для всех экранов.

<?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.admin1.constraintlayoutsample.MainActivity"
    android:background="#E0E0E0">

    <ImageView
        android:src="@mipmap/ic_launcher"
        android:id="@+id/imageView"
        android:layout_width="0dp"
        android:layout_height="0dp"
        app:layout_constraintDimensionRatio="H,16:9"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintEnd_toEndOf="parent" />

    <TextView
        android:id="@+id/textView6"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Login"
        android:textSize="30dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toBottomOf="@id/imageView"
        app:layout_constraintVertical_bias="0.128" />


    <TextView
        android:id="@+id/textView3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginBottom="8dp"
        android:text="Email"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.0"
        app:layout_constraintStart_toStartOf="@+id/editText"
        app:layout_constraintTop_toBottomOf="@+id/textView6"
        app:layout_constraintVertical_bias="0.10" />


    <EditText
        android:id="@+id/editText"
        android:layout_width="wrap_content"
        android:layout_height="44dp"
        android:layout_marginEnd="8dp"
        android:layout_marginStart="8dp"
        android:alpha="0.23"
        android:background="@drawable/textviewshape"
        android:ems="10"
        android:inputType="textPersonName"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/textView3" />


    <TextView
        android:id="@+id/textView4"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginBottom="8dp"
        android:text="Password"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.0"
        app:layout_constraintStart_toStartOf="@+id/editText"
        app:layout_constraintTop_toBottomOf="@+id/editText"
        app:layout_constraintVertical_bias="0.100" />


    <EditText
        android:id="@+id/editText2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:alpha="0.23"
        android:background="@drawable/textviewshape"
        android:ems="10"
        android:inputType="textPersonName"
        app:layout_constraintHorizontal_bias="0.0"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="@+id/textView4"
        app:layout_constraintTop_toBottomOf="@+id/textView4" />


    <Button
        android:id="@+id/button3"
        android:layout_width="175dp"
        android:layout_height="wrap_content"
        android:layout_marginBottom="8dp"
        android:layout_marginEnd="8dp"
        android:layout_marginStart="8dp"
        android:layout_marginTop="8dp"
        android:background="@drawable/buttonshape"
        android:text="Login"
        android:textColor="@android:color/black"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/editText2"
        app:layout_constraintVertical_bias="0.20"/>


</android.support.constraint.ConstraintLayout>

Когда я вижу этот дизайн на 5-дюймовом или 6-дюймовом экране, он выглядит хорошо.Но когда я вижу в 4.7 или ниже размер экрана, он не вписывается в экран.Пожалуйста, дайте мне знать, как использовать макет ограничения для всех размеров экрана.И, пожалуйста, предложите несколько образцов / учебник для этого.

5 inch screen design

3.7 inch screen design

1 Ответ

0 голосов
/ 25 октября 2018

Я думаю, что для того, чтобы сделать ваш экран регулируемым, вы можете использовать одно из нескольких решений:

  1. Сделайте ваш просмотр между height или margin в процентах.Используя Guideline или используйте вес (например, layout_constraintHorizontal_weight).Для получения дополнительной информации проверьте эту тему это о весе.
  2. Сделайте ваши изображения и / или текстовые вводы, кнопку, чтобы использовать другой масштаб для другого размера экрана.
  3. Сделайте ваш экран прокручиваемым, если нет сверхуЭто относится к вашему решению.
...