Почему мое приложение выглядит по-разному в режиме конструктора и эмулятора? - PullRequest
0 голосов
/ 24 сентября 2018

Я программирую приложение и у меня есть индивидуальный дизайн для моего приложения, проблема в том, что пользовательский интерфейс выглядит идеально в режиме дизайна, но в режиме выполнения (на эмуляторе и реальном устройстве) он выглядит по-разному.Любая подсказка, почему ???Спасибо всем.

Моя задача сделать так, чтобы пользовательский интерфейс в эмуляторе выглядел так же, как в режиме конструктора.

enter image description here

Вот некоторыекод:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 
    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:orientation="vertical"
    android:background="@drawable/bg"
    android:weightSum="8">
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight=".8">
    </LinearLayout>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight=".8">
    </LinearLayout>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:gravity="center"
        android:layout_marginLeft="50sp"
        android:layout_marginRight="50sp"
        android:padding="4dp"
        android:layout_weight=".8">
    <Button
        android:text="Start"
        android:textColor="#0495d4"
        android:textAllCaps="false"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/btnStart"
        android:layout_gravity="center" />
    </LinearLayout>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:gravity="center"
        android:layout_marginLeft="50sp"
        android:layout_marginRight="50sp"
        android:padding="4dp"
        android:layout_weight=".8">
    <Button
        android:text="Followings"
        android:textColor="#0495d4"
        android:textAllCaps="false"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/btnFollowings"
        android:layout_gravity="center" />
    </LinearLayout>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight=".8">
    </LinearLayout>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:gravity="center"
        android:layout_weight=".8"
        android:orientation="horizontal"
        android:weightSum="3">
        <LinearLayout
            android:layout_width="0dp"
            android:layout_height="fill_parent"
            android:layout_weight=".2"/>
        <LinearLayout
            android:layout_width="0dp"
            android:padding="2sp"
            android:layout_height="fill_parent"
            android:layout_weight="2.6">
    <EditText
        android:hint="Pin Code"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:textSize="16dp"
        android:textColor="@android:color/white"
        android:fontFamily="sans-serif-medium"
        android:textColorHint="@android:color/white"
        android:backgroundTint="@android:color/white"
        android:id="@+id/txtPinCode" />
        </LinearLayout>
        <LinearLayout
            android:layout_width="0dp"
            android:layout_height="fill_parent"
            android:layout_weight=".2"/>

    </LinearLayout>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:gravity="center"


        android:layout_weight=".8"
        android:orientation="horizontal"
        android:weightSum="3">
        <LinearLayout
        android:layout_width="0dp"
        android:layout_height="fill_parent"
        android:layout_weight=".8"/>
        <LinearLayout
            android:layout_width="0dp"
            android:padding="10sp"
            android:gravity="center"

            android:layout_height="fill_parent"
            android:layout_weight="1.4">
    <Button
        android:text="Verify Pin"
        android:textColor="#0495d4"
        android:textAllCaps="false"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/btnSavePin" 
        android:layout_gravity="center" />
        </LinearLayout>
        <LinearLayout
            android:layout_width="0dp"
            android:layout_height="fill_parent"
            android:layout_weight=".8"/>

    </LinearLayout>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="2.4">

    </LinearLayout>
</LinearLayout>

Ответы [ 2 ]

0 голосов
/ 24 сентября 2018

Причина, по которой дизайны выглядят иначе, заключается в том, что конфигурация экрана эмулятора отличается от конфигурации, используемой для визуализации предварительного просмотра дизайна.

В раскрывающемся меню (см. Скриншот 1 ) изРедактор макета попытается найти конфигурацию, которая соответствует вашему эмулируемому устройству как в измерении, так и в dpi.Таким образом, предварительный просмотр будет более точным.

Device picker

Чтобы узнать, какая конфигурация экрана у вашего эмулятора, просто перейдите в диспетчер устройств (скриншот )2 ) и см. Столбец разрешения.

Device Manager

0 голосов
/ 24 сентября 2018

На разных устройствах (эмуляторах устройств) и на разных версиях андроида разные значения стандартных стилей (textView, поле ввода и т. Д.).Дизайнер показывает все дословно, виджеты устройства смешаны со стилями из стандартной библиотеки Android (конкретная версия)

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...