макет на эмуляторе отличается от предварительного просмотра в андроид студии - PullRequest
0 голосов
/ 11 мая 2018

Итак, я запускаю свое приложение на эмуляторе nexus 5 (1080x1920, dpi: 480) и nexus 6P (1440x2560, dpi: 560). Я использовал формулу, предоставленную этой ссылкой , чтобы вычислить наименьшую ширину (sw).

Nexus 5: 1080 / (480/160) = 360. Nexus 6P: 1440 / (560/160) = 411.

Проблема 1: Я создал стандартную раскладку sw320 для обоих этих телефонов. Одно из изображений на Nexus 5 драматично уменьшит его размер по сравнению с предварительным просмотром и 6P, все остальные изображения выглядят нормально.

предварительный просмотр показан здесь , показан Nexus 6P здесь , показан Nexus 5 здесь .

Кроме того, я замечаю, что когда я перемещаюсь по изображению сигнальной полосы в предварительном просмотре студии Android, изображение меняет размер.

Проблема 2: Я создал различные макеты SW, показанные здесь . Тем не менее, предварительный просмотр макета по умолчанию все испорчен, показанный здесь . Раньше я добавлял все макеты sw, это выглядит как this .

Вопрос 1: В чем причина разницы в изображении между двумя телефонами?

Вопрос 2: При предварительном просмотре в Android Studio, какова причина изменения размера изображения при его перетаскивании?

Вопрос 3: В чем причина неправильной компоновки по умолчанию, даже если я не изменил код в этом файле?

Обновление с кодом XML:

<RelativeLayout 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="@drawable/joystick_background"
tools:context="com.example.android.toybot.JoyStickActivity">

<RelativeLayout
    android:id="@+id/relativeLayout"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"

    android:layout_weight="0.5"

    android:layout_marginTop="70dp"
    android:layout_alignParentTop="true"
    android:layout_centerHorizontal="true">

    <ImageView
        android:id="@+id/imageView4"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginEnd="11dp"
        android:layout_below="@+id/exit_switch_id"

        android:scaleX="0.5"
        android:scaleY="0.5"
        android:layout_marginTop="1dp"
        android:layout_marginLeft="30dp"
        android:src="@drawable/text_exit"/>


    <ImageView
        android:id="@+id/imageView8"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:scaleX="0.5"
        android:scaleY="0.5"
        android:src="@drawable/text_turbo"
        android:layout_alignTop="@+id/imageView4"
        android:layout_toEndOf="@+id/exit_switch_id"
        android:layout_alignBottom="@+id/imageView4" />

    <Switch
        android:id="@+id/exit_switch_id"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:rotation="90"
        android:scaleX="0.8"
        android:scaleY="0.8"
        android:thumb="@drawable/joystick_hat"
        android:track="@drawable/joystick_lever_switch"
        android:layout_alignBaseline="@+id/turbo_switch_id"
        android:layout_alignBottom="@+id/turbo_switch_id"
        android:layout_alignParentStart="true"
        android:layout_marginStart="14dp" />

    <Switch
        android:id="@+id/turbo_switch_id"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="14dp"
        android:rotation="90"
        android:scaleX="0.8"
        android:scaleY="0.8"
        android:thumb="@drawable/joystick_hat"
        android:track="@drawable/joystick_lever_switch"
        android:layout_alignParentTop="true"
        android:layout_toEndOf="@+id/exit_switch_id" />

</RelativeLayout>

<LinearLayout
    android:id="@+id/linearLayout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    android:layout_alignParentBottom="true"
    android:layout_alignParentStart="true">

    <com.example.android.toybot.JoyStickView
        android:id="@+id/joystickLeft"
        android:layout_width="wrap_content"
        android:layout_height="200dp"
        android:layout_alignParentStart="true"
        android:layout_weight="0.5" />


    <com.example.android.toybot.JoyStickView
        android:id="@+id/joystickRight"
        android:layout_width="wrap_content"
        android:layout_height="200dp"
        android:layout_weight="0.5" />

</LinearLayout>

<LinearLayout
    android:id="@+id/linearLayout3"
    android:layout_width="100dp"
    android:layout_height="wrap_content"
    android:layout_weight="0.5"
    android:orientation="horizontal"
    android:layout_above="@+id/linearLayout4"
    android:layout_alignParentStart="true">

    <TextView
        android:id="@+id/textView3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="RM:" />

    <TextView
        android:id="@+id/x_coo"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="x_coo" />

</LinearLayout>

<LinearLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    android:id="@+id/linearLayout5"
    android:layout_above="@+id/linearLayout3"
    android:layout_alignParentStart="true">

    <TextView
        android:id="@+id/textview6"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"

        android:layout_alignBaseline="@+id/dir_view"
        android:layout_alignBottom="@+id/dir_view"
        android:layout_marginEnd="15dp"
        android:layout_toStartOf="@+id/dir_view"
        android:layout_weight="0.04"
        android:text="Direction:" />

    <TextView
        android:id="@+id/dir_view"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_above="@+id/linearLayout3"
        android:layout_marginStart="15dp"
        android:layout_toEndOf="@+id/linearLayout2"
        android:layout_weight="0.01"
        android:text="TextView" />
</LinearLayout>

<LinearLayout
    android:layout_width="100dp"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    android:id="@+id/linearLayout4"
    android:layout_above="@+id/linearLayout"
    android:layout_alignParentStart="true"
    android:layout_marginBottom="17dp">

    <TextView
        android:id="@+id/ly_id"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="LM:" />

    <TextView
        android:id="@+id/ly_id_display"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="left_y_coo" />

</LinearLayout>

<TextView
    android:id="@+id/RSSI_id"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_above="@+id/linearLayout5"
    android:layout_alignEnd="@+id/linearLayout3"
    android:layout_marginBottom="14dp"
    android:text="rssi value" />

<FrameLayout
    android:id="@+id/singal_bar_layout"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginBottom="17dp"
    android:layout_above="@+id/RSSI_id"
    android:layout_alignParentEnd="true">


    <ImageView
        android:scaleX="0.8"
        android:scaleY="0.8"
        android:id="@+id/signal_bar_0"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:visibility="visible"
        android:src="@drawable/signal_bars0_01" />

    <ImageView
        android:scaleX="0.8"
        android:scaleY="0.8"
        android:id="@+id/signal_bar_1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/signal_bars1_01"
        android:visibility="invisible" />

    <ImageView
        android:scaleX="0.8"
        android:scaleY="0.8"
        android:id="@+id/signal_bar_2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/signal_bars2_01"
        android:visibility="invisible" />

    <ImageView
        android:scaleX="0.8"
        android:scaleY="0.8"
        android:id="@+id/signal_bar_3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/signal_bars3_01"
        android:visibility="invisible" />

    <ImageView
        android:id="@+id/signal_bar_4"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:scaleX="0.8"
        android:scaleY="0.8"
        android:src="@drawable/signal_bars4_01"
        android:visibility="invisible" />

</FrameLayout>

1 Ответ

0 голосов
/ 25 мая 2018

Чтобы решить мою проблему 1, вместо создания нарисованных файлов я создал файлы mipmap, таким образом, изображение остается в одном размере, и это сработало для меня.

Проблема 2, причина, по которой предыдущий был испорчен, заключается в том, что устройство в редакторе было в виде Apple Watch, а не в реальном виде телефона, который является просто квадратом.

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