Дизайн макета Android не совпадает с приложением при работе на мобильном телефоне - PullRequest
0 голосов
/ 22 декабря 2019

Дизайн моего макета не одинаков в предварительном просмотре Android Studio и в моем мобильном телефоне (Samsung s8). Я пытаюсь сделать так, чтобы обе кнопки были выровнены по горизонтали (т.е. чтобы они начинались и заканчивались в одной и той же оси x). По словам дизайнера, кажется, что они выровнены так, как я хочу, но на самом деле (в устройстве) это не так.

Снимок экрана из Android Studio Designer:

Designer

Снимок экрана от Samsung S8:

Samsung

мой Xml:

 <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="match_parent">

    <TextView
        android:id="@+id/textView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center_horizontal"
        android:text="Menu"
        android:textSize="50sp" />

    <EditText
        android:id="@+id/editText3"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:ems="10"
        android:inputType="textMultiLine"
        android:text="Select a layout type to view an example. The onClick attribute of each button will call a method which executes setContentView to load the new layout"/>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal">

        <TextView
            android:id="@+id/textView2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center_vertical"
            android:layout_weight="0.59"
            android:text="Load ConstraintLayout"
            android:layout_marginLeft="8dp"
            android:textSize="20dp" />

        <Button
            android:id="@+id/button1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="0.41"
            android:text="Load"
            android:layout_marginRight="8dp"/>


    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal">

        <TextView
            android:id="@+id/textView3"
            android:layout_width="30dp"
            android:layout_height="wrap_content"
            android:layout_weight="0.7"
            android:layout_gravity="center_vertical"
            android:textSize="20dp"
            android:text="Load TableLayout"
            android:layout_marginLeft="8dp"/>

        <Button
            android:id="@+id/button2"
            android:layout_width="30dp"
            android:layout_height="wrap_content"
            android:layout_weight="0.3"
            android:text="Load"
            android:layout_marginRight="8dp"/>

    </LinearLayout>

    <RatingBar
        android:id="@+id/ratingBar4"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="15dp"
        android:layout_marginRight="15dp"
        android:layout_marginTop="75dp"/>


</LinearLayout>

Кто-нибудь может понять причину несоответствия?

1 Ответ

0 голосов
/ 22 декабря 2019

Это потому, что вы используете margin с dp, если вы выиграли, чтобы определить в процентах, я рекомендовал использовать ограничение ограничений, отметьте это Как заставить ConstraintLayout работать с процентными значениями?

...