свободное место в редакторе дизайна, но не на устройстве?

#android

#Android

Вопрос:

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

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

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

и вот XML-код :

 <?xml version="1.0" encoding="utf-8"?>
<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"
    tools:context="com.example.MyPfe.ClientInterface">

    <LinearLayout
        android:id="@ id/global_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        android:layout_above="@id/Butt_layout"
        android:weightSum="2"


        >


        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:orientation="vertical"
            android:weightSum="1"
            android:layout_weight="1">


            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="0dp"
                android:layout_weight="1"
                android:gravity="center_horizontal"
                android:orientation="vertical"
                >

                <ImageView
                    android:layout_width="50dp"
                    android:layout_height="50dp"
                    android:padding="10dp"
                    android:src="@drawable/ic_car" />

                <Button
                    android:layout_width="200dp"
                    android:layout_height="30dp"
                    android:textAlignment="center"
                    android:text="Document à transmettre"
                    android:textSize="12dp"
                    android:textColor="@color/backgroundcolor"
                    android:layout_marginTop="5dp"
                    android:background="@color/sogreen"/>


                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:gravity="center"
                    android:layout_marginTop="20dp"
                    android:orientation="vertical">

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:textColor="@color/textcolor"
                    android:text="CONTRAT AUTO N°"/>

                <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_marginTop="3dp"
                        android:text="nome et prenom"
                    android:textColor="@color/textcolor"/>



              </LinearLayout>
                <View
                    android:layout_marginTop="10dp"
                    android:layout_width="250dp"
                    android:layout_height="1dp"
                    android:background="@android:color/darker_gray"/>

                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:gravity="center"
                    android:layout_marginTop="10dp"
                    android:orientation="vertical">

                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:textColor="@color/textcolor"
                        android:text="Début du contrat le"/>

                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_marginTop="3dp"
                        android:text="Échéance le"
                        android:textColor="@color/textcolor"/>



                </LinearLayout>
            </LinearLayout>





        </LinearLayout>












        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_gravity="center"
            android:layout_weight="1"
            android:orientation="vertical"
            android:weightSum="2"

            >

            <LinearLayout

                android:layout_width="match_parent"
                android:layout_height="0dp"
                android:layout_weight="1"
                android:layout_gravity="center_horizontal"

                android:gravity="center_vertical"
                android:orientation="horizontal"
                android:weightSum="2">

                <LinearLayout
                    android:id="@ id/cons_cont_lin"
                    android:layout_width="0dp"
                    android:layout_height="match_parent"
                    android:layout_weight="1"
                    android:clickable="true"
                    android:gravity="center"
                    android:orientation="vertical">

                    <ImageView
                        android:layout_width="50dp"
                        android:layout_height="50dp"
                        android:background="@drawable/cerclebackgroundgreen"
                        android:padding="10dp"
                        android:src="@drawable/ic_consulter_contrat" />

                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_marginTop="10dp"
                        android:text="Consulter mon                    contrat"
                        android:textAlignment="center"
                        android:textSize="14sp"
                        android:textStyle="bold" />

                </LinearLayout>

                <LinearLayout
                    android:layout_width="0dp"
                    android:layout_height="match_parent"
                    android:layout_weight="1"
                    android:gravity="center"
                    android:orientation="vertical">

                    <ImageView
                        android:layout_width="50dp"
                        android:layout_height="50dp"
                        android:background="@drawable/cerclebackgroundgreen"
                        android:padding="10dp"
                        android:src="@drawable/ic_consulter_contrat" />

                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_marginTop="10dp"
                        android:text="Modifier mon                      contrat"
                        android:textAlignment="center"
                        android:textSize="14sp"
                        android:textStyle="bold" />

                </LinearLayout>

            </LinearLayout>

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="0dp"
                android:layout_weight="1"
                android:layout_gravity="center_horizontal"
                android:gravity="center_vertical"
                android:orientation="horizontal"
                android:weightSum="2">

                <LinearLayout
                    android:layout_width="0dp"
                    android:layout_height="match_parent"
                    android:layout_weight="1"
                    android:gravity="center"
                    android:orientation="vertical">

                    <ImageView
                        android:layout_width="50dp"
                        android:layout_height="50dp"
                        android:background="@drawable/cerclebackgroundgreen"
                        android:padding="10dp"
                        android:src="@drawable/ic_consulter_contrat" />

                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_marginTop="10dp"
                        android:text="Suivre un                             sinistre"
                        android:textAlignment="center"
                        android:textSize="14sp"
                        android:textStyle="bold" />

                </LinearLayout>

                <LinearLayout
                    android:layout_width="0dp"
                    android:layout_height="match_parent"
                    android:layout_weight="1"
                    android:gravity="center"
                    android:orientation="vertical">

                    <ImageView
                        android:layout_width="50dp"
                        android:layout_height="50dp"
                        android:background="@drawable/cerclebackgroundgreen"
                        android:padding="10dp"
                        android:src="@drawable/ic_consulter_contrat" />

                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_marginTop="10dp"
                        android:text="Déclarer un                       sininstre"
                        android:textAlignment="center"
                        android:textSize="14sp"
                        android:textStyle="bold" />

                </LinearLayout>


            </LinearLayout>


        </LinearLayout>





    </LinearLayout>



    <RelativeLayout
        android:id="@ id/Butt_layout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_marginTop="8dp"
        android:orientation="horizontal"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent">


        <Button
            android:id="@ id/bt_depannage"
            android:layout_width="match_parent"
            android:layout_height="50dp"
            android:background="@color/sogreen"
            android:text="URGENCE ET DÉPANNAGE"
            android:textAlignment="center"
            android:textColor="@color/backgroundcolor"
            android:textSize="15sp" />


    </RelativeLayout>
</RelativeLayout>
  

Комментарии:

1. Попробуйте использовать другое устройство в preview . Вероятно, ваш эмулятор имеет другой размер, чем в предварительном просмотре (я вижу Pixel с API 28 помощью)

2. Я пробовал то же самое… предварительный просмотр не изменился.

3. Главный вопрос — вам нужно это место На УСТРОЙСТВЕ или нет?

Ответ №1:

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

Из того, что я вижу, нижняя часть, содержащая значки, выровнена по базовой линии / дну и т.д. родительского контейнера или что-то в этом роде. Я думаю, что ваше устройство имеет экран 4,5 » или 5 «, в то время как ваш дизайнер и ваш эмулятор имеют экран 6 «.