Не могли бы вы объяснить, почему Layout в Android Studio отличается от Layout на реальном устройстве? - PullRequest
0 голосов
/ 10 мая 2018

Я пытаюсь создать группу папок для каждого размера (ldpi, mdpi e.t.c.) и размеров для каждой папки. Проблема в том, что когда я тестирую это на реальном устройстве, расположение элементов меняется. Речь идет не о привязках, а о полях и т. Д. Устройство правильно выбрано, я это проверил. Но когда я выбираю в «Устройство в редакторе» мой телефон с тем же разрешением и размером дисплея, расположение там и в моем реальном телефоне отличается, как работать таким образом ??

Мой макет, если это необходимо:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/cards"
    android:orientation="vertical">


    <ImageView
        android:id="@+id/card_image"
        android:layout_width="match_parent"
        android:layout_height="@dimen/cardHeigh"
        app:srcCompat="@drawable/black_hall" />

    <ImageButton
        android:id="@+id/button_home"
        android:layout_width="@dimen/homeWidth"
        android:layout_height="@dimen/homeHeigh"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:layout_alignParentTop="true"
        android:layout_marginLeft="@dimen/homeMarginLeft"
        android:layout_marginTop="@dimen/homeMarginTop"
        android:background="@color/TransperantColor"
        android:scaleType="centerInside"
        android:scaleX="0.8"
        android:scaleY="0.8"
        app:srcCompat="@drawable/home_light" />

    <ImageButton
        android:id="@+id/button_confirm"
        android:layout_width="@dimen/confirmWidth"
        android:layout_height="@dimen/confirmHeigh"
        android:layout_alignParentEnd="true"
        android:layout_alignParentRight="true"
        android:layout_alignParentTop="true"
        android:layout_marginRight="@dimen/confirmMarginRight"
        android:layout_marginTop="@dimen/confirmMarginTop"
        android:background="@color/TransperantColor"
        android:scaleType="centerInside"
        android:scaleX="0.8"
        android:scaleY="0.8"
        app:srcCompat="@drawable/confirm_light" />

    <TextView
        android:id="@+id/head_name"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/card_image"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="@dimen/headMarginTop"
        android:padding="@dimen/headPadding"
        android:textColor="@color/White"
        android:textSize="@dimen/headTextSize"
        android:textStyle="bold"/>

    <LinearLayout
        android:id="@+id/text"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/head_name"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="@dimen/textLinearMarginTop"
        android:orientation="horizontal">

        <TextView
            android:id="@+id/monfri"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:gravity="right"
            android:paddingRight="@dimen/monfriPaddingRight"
            android:text="xxhdpi"
            android:textColor="@color/White"
            android:typeface="normal />

        <TextView
            android:id="@+id/mon_fri_text"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:textColor="@color/myTextColor"/>

    </LinearLayout>

    <LinearLayout
        android:id="@+id/time"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/text"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="@dimen/timeLinearMarginTop"
        android:orientation="horizontal">

        <TextView
            android:id="@+id/sat"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:gravity="right"
            android:paddingRight="@dimen/satPaddingRight"
            android:text="@string/sat"
            android:textColor="@color/White"/>

        <TextView
            android:id="@+id/sat_text"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:textColor="@color/myTextColor" />
    </LinearLayout>

    <LinearLayout
        android:id="@+id/sun"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/time"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="@dimen/sunLinearmarginTop"
        android:orientation="horizontal">

        <TextView
            android:id="@+id/sunday"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:gravity="right"
            android:paddingRight="@dimen/sunPaddingRight"
            android:text="@string/sun"
            android:textColor="@color/White"
            app:fontFamily="@font/futura_pt_light" />

        <TextView
            android:id="@+id/sun_text"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:textColor="@color/myTextColor" />
    </LinearLayout>

    <TextView
        android:id="@+id/descr"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/sun"
        android:layout_centerHorizontal="true"
        android:layout_margin="@dimen/descrMargin"
        android:padding="@dimen/descrPadding"
        android:textColor="@color/myTextColor"
        android:textStyle="italic"
        android:typeface="serif"/>

    <LinearLayout
        android:id="@+id/images_inter"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_below="@+id/descr"
        android:layout_marginLeft="@dimen/interLinearMarginLeft"
        android:orientation="vertical">

        <ImageView
            android:id="@+id/phone"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:adjustViewBounds="true"
            android:padding="@dimen/phonePadding"
            android:scaleType="centerInside"
            app:srcCompat="@drawable/phone_ico" />

        <ImageView
            android:id="@+id/geo"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:adjustViewBounds="true"
            android:padding="@dimen/geoPadding"
            android:scaleType="centerInside"
            app:srcCompat="@drawable/geo_ico" />

    </LinearLayout>

    <LinearLayout
        android:id="@+id/info"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_alignTop="@+id/images_inter"
        android:layout_marginLeft="@dimen/infoLinearMarginLeft"
        android:layout_toRightOf="@+id/images_inter"
        android:orientation="vertical">

        <TextView
            android:id="@+id/phone1_name"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="0.4"
            android:gravity="bottom"
            android:textColor="@color/White"
            android:textStyle="bold" />

        <TextView
            android:id="@+id/phone2_name"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="0.4"
            android:gravity="top"
            android:textColor="@color/White"
            android:textStyle="bold"/>

        <TextView
            android:id="@+id/adress"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:gravity="center_vertical"
            android:textColor="@color/White"
            android:textStyle="bold" />
    </LinearLayout>

</RelativeLayout>

1 Ответ

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

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

С учетом вышесказанного, возможно, макет вашего приложения выглядит по-другому на вашем устройстве из-за плотности экрана вашего устройства и используемых вами единиц измерения.

Если вы используете px, элементы будут выглядеть больше на экранах низкой плотности и меньше на экранах высокой плотности.

-dp или «пиксели, независимые от плотности», будут иметь одинаковые размеры на любом экране. Я рекомендую использовать дп.

-sp это как do, но для шрифтов.

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