0

Создал дизайн активности. Запустил дабы проверить все. Оказалось, что дизайн на превью отличается от самого дизайна в эмуляторе (Ужасный градиент и кнопки налезают друг на друга).

Превью

Эмулятор

Код

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.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"
    android:background="@color/colorBackground"
    tools:context=".MainActivity">


    <androidx.constraintlayout.widget.ConstraintLayout
        android:layout_width="match_parent"
        android:layout_height="250dp"
        android:layout_marginTop="100dp"
        android:layout_marginBottom="100dp"
        android:background="@drawable/sign_in_gradient_bar"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintTop_toTopOf="parent">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginStart="20dp"
            android:layout_marginTop="20dp"
            android:layout_marginEnd="20dp"
            android:fontFamily="sans-serif-light"
            android:text="Введите данные"
            android:textSize="20sp"
            android:textColor="@color/colorWhite"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent" />

        <EditText
            android:id="@+id/MainActivity_EditText_Email"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginStart="50dp"
            android:layout_marginTop="80dp"
            android:layout_marginEnd="50dp"
            android:background="@drawable/edit_text_style"
            android:fontFamily="sans-serif-light"
            android:gravity="center"
            android:hint="Email"
            android:textSize="20sp"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent" />

        <EditText
            android:id="@+id/MainActivity_EditText_Password"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginStart="50dp"
            android:layout_marginEnd="50dp"
            android:layout_marginBottom="80dp"
            android:background="@drawable/edit_text_style"
            android:fontFamily="sans-serif-light"
            android:gravity="center"
            android:hint="Пароль"
            android:textSize="20sp"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent" />

        <Button
            android:id="@+id/MainActivity_Button_Login"
            android:layout_width="100dp"
            android:layout_height="30dp"
            android:layout_marginStart="50dp"
            android:layout_marginTop="30dp"
            android:background="@drawable/button_style"
            android:fontFamily="sans-serif-light"
            android:text="Войти"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/MainActivity_EditText_Password" />

        <Button
            android:id="@+id/MainActivity_Button_Register"
            android:layout_width="200dp"
            android:layout_height="30dp"
            android:layout_marginTop="30dp"
            android:layout_marginEnd="50dp"
            android:background="@drawable/button_style"
            android:fontFamily="sans-serif-light"
            android:text="Зарегистрироваться"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/MainActivity_EditText_Password" />

    </androidx.constraintlayout.widget.ConstraintLayout>


</androidx.constraintlayout.widget.ConstraintLayout>

1 ответ 1

1

У вас статические размеры кнопок. Возможно, в Андроид Студио у Вас большой размер экрана, а при эмуляции - маленький, а т.к. размеры статические, то резльтат будет такой, как у Вас. И зачем делать два одинаковые лаяуты ? Делали бы в главном. Вообще, сделайте для этих 2ух кнопок LinearLayout, и android:layout_width сделайте равным 0 для каждой кнопки. Также добавьте новый параметр weight, для логин кнопки установите значение 1, а для регистрации 2.

3
  • Я делал такое же в другом проекте, но там все работало хорошо, не знаю, что делать
    –  loveu
    15 ноя 2019 в 14:55
  • Сделайте LinearLayout и вставьте туда эти две кнопки, затем проделайте то, что написал выше.
    – Mako Storm
    15 ноя 2019 в 15:07
  • А, все, разобрался, благодарю за помощь!
    –  loveu
    15 ноя 2019 в 16:37

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.