Android поддерживает ошибку разных размеров экрана - PullRequest
0 голосов
/ 08 мая 2019

У меня проблема с поддержкой разных размеров экрана. Что бы я ни делал, приложение всегда выбирает макет xhdpi. Я тестировал на двух смартфонах. Samsung Core II и Huawei Y6. Это измерение обоих смартфонов.

Samsung Core II Android 4.4
480x800
Screen density 1.5 which is hdpi

Huawei y6 Android:9 
720x1422 
screen density 2.0 which is xhdpi

Я создал два макета

mylayout.xml
      mylayout.xml (hdpi)
      mylayout.xml (xhdpi)

Теперь при запуске приложения на устройстве макет xhdpi появляется на обоих смартфонах. Как я могу это исправить? Вот XML для обоих макетов

для hdpi

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 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="@color/lightgray">

    <ImageView
        android:id="@+id/image_view_blur"
        android:layout_width="0dp"
        android:layout_height="100dp"
        android:background="@color/colorPrimary"
        android:contentDescription="@null"
        android:scaleType="fitXY"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.0"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.0">


    </ImageView>

    <TextView
        android:id="@+id/tv_nick_name"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="16dp"
        android:layout_marginLeft="16dp"
        android:layout_marginTop="8dp"
        android:layout_marginEnd="16dp"
        android:layout_marginRight="16dp"
        android:textColor="@color/black"
        android:textSize="22sp"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.53"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/iv_user_image" />

    <spinkitview.SpinKitView
        android:id="@+id/iv_waiting"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_vertical|center_horizontal"
        android:layout_marginStart="8dp"
        android:layout_marginLeft="8dp"
        android:layout_marginEnd="8dp"
        android:layout_marginRight="8dp"
        android:visibility="invisible"
        app:SpinKit_Color="@color/colorPrimary"
        app:SpinKit_Style="MultiplePulse"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.498"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/tv_nick_name" />


    <TextView
        android:id="@+id/tv_no_internet"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="8dp"
        android:background="@color/yellow"
        android:gravity="center"
        android:text="@string/no_internet"
        android:textColor="@color/black"
        android:textSize="16sp"
        android:visibility="invisible"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.0"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/iv_conf_call" />

    <ImageView
        android:id="@+id/iv_share"
        android:layout_width="wrap_content"
        android:layout_height="40dp"
        android:layout_marginTop="24dp"
        android:background="@drawable/ripple_with_background"
        android:contentDescription="@null"
        android:onClick="ivShare"
        android:padding="10dp"
        android:src="@drawable/ic_share"
        android:tint="@color/white"
        app:layout_constraintEnd_toStartOf="@+id/ic_contact_us"
        app:layout_constraintHorizontal_bias="0.5"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/tv_no_internet" />


    <ImageView
        android:id="@+id/iv_conf_call"
        android:layout_width="45dp"
        android:layout_height="40dp"
        android:layout_marginStart="8dp"
        android:layout_marginLeft="8dp"
        android:layout_marginTop="8dp"
        android:layout_marginEnd="16dp"
        android:layout_marginRight="16dp"
        android:background="@drawable/ripple_with_background"
        android:contentDescription="@null"
        android:onClick="btnCall_Clicked"
        android:padding="10dp"
        android:src="@android:drawable/sym_action_call"
        android:tint="@color/white"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/iv_waiting" />

    <ImageView
        android:id="@+id/ic_contact_us"
        android:layout_width="wrap_content"
        android:layout_height="40dp"
        android:background="@drawable/ripple_with_background"
        android:contentDescription="@null"
        android:onClick="ContactUs"
        android:padding="10dp"
        android:src="@drawable/ic_contact_us"
        android:tint="@color/white"
        app:layout_constraintBottom_toBottomOf="@+id/iv_share"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.5"
        app:layout_constraintStart_toEndOf="@+id/iv_share"
        app:layout_constraintTop_toTopOf="@+id/iv_share"
        app:layout_constraintVertical_bias="0.0" />


    <ImageView
        android:id="@+id/iv_user_image"
        android:layout_width="90dp"
        android:layout_height="90dp"
        android:layout_marginStart="8dp"
        android:layout_marginLeft="8dp"
        android:layout_marginEnd="8dp"
        android:layout_marginRight="8dp"
        android:background="@drawable/image_round_background"
        android:contentDescription="@null"
        android:padding="10dp"
        android:src="@drawable/unknown_image"
        android:tint="@color/colorPrimary"
        app:layout_constraintBottom_toBottomOf="@+id/image_view_blur"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/image_view_blur"
        app:layout_constraintVertical_bias="0.75" />
</android.support.constraint.ConstraintLayout>

Для xhdpi

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 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="@color/lightgray">

    <ImageView
        android:id="@+id/image_view_blur"
        android:layout_width="0dp"
        android:layout_height="200dp"
        android:background="@color/colorPrimary"
        android:contentDescription="@null"
        android:scaleType="fitXY"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.0"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.0">


    </ImageView>

    <TextView
        android:id="@+id/tv_nick_name"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="16dp"
        android:layout_marginLeft="16dp"
        android:layout_marginTop="8dp"
        android:layout_marginEnd="16dp"
        android:layout_marginRight="16dp"
        android:textColor="@color/black"
        android:textSize="22sp"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.53"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/iv_user_image" />

    <spinkitview.SpinKitView
        android:id="@+id/iv_waiting"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_vertical|center_horizontal"
        android:layout_marginStart="8dp"
        android:layout_marginLeft="8dp"
        android:layout_marginEnd="8dp"
        android:layout_marginRight="8dp"
        android:visibility="invisible"
        app:SpinKit_Color="@color/colorPrimary"
        app:SpinKit_Style="MultiplePulse"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.498"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/tv_nick_name" />


    <TextView
        android:id="@+id/tv_no_internet"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="8dp"
        android:background="@color/yellow"
        android:gravity="center"
        android:text="@string/no_internet"
        android:textColor="@color/black"
        android:textSize="16sp"
        android:visibility="invisible"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.0"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/iv_conf_call" />

    <ImageView
        android:id="@+id/iv_share"
        android:layout_width="wrap_content"
        android:layout_height="80dp"
        android:layout_marginTop="24dp"
        android:background="@drawable/ripple_with_background"
        android:contentDescription="@null"
        android:onClick="ivShare"
        android:padding="10dp"
        android:src="@drawable/ic_share"
        android:tint="@color/white"
        app:layout_constraintEnd_toStartOf="@+id/ic_contact_us"
        app:layout_constraintHorizontal_bias="0.5"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/tv_no_internet" />


    <ImageView
        android:id="@+id/iv_conf_call"
        android:layout_width="90dp"
        android:layout_height="90dp"
        android:layout_marginStart="8dp"
        android:layout_marginLeft="8dp"
        android:layout_marginTop="8dp"
        android:layout_marginEnd="16dp"
        android:layout_marginRight="16dp"
        android:background="@drawable/ripple_with_background"
        android:contentDescription="@null"
        android:onClick="btnCall_Clicked"
        android:padding="10dp"
        android:src="@android:drawable/sym_action_call"
        android:tint="@color/white"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/iv_waiting" />

    <ImageView
        android:id="@+id/ic_contact_us"
        android:layout_width="wrap_content"
        android:layout_height="80dp"
        android:background="@drawable/ripple_with_background"
        android:contentDescription="@null"
        android:onClick="ContactUs"
        android:padding="10dp"
        android:src="@drawable/ic_contact_us"
        android:tint="@color/white"
        app:layout_constraintBottom_toBottomOf="@+id/iv_share"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.5"
        app:layout_constraintStart_toEndOf="@+id/iv_share"
        app:layout_constraintTop_toTopOf="@+id/iv_share"
        app:layout_constraintVertical_bias="0.0" />


    <ImageView
        android:id="@+id/iv_user_image"
        android:layout_width="180dp"
        android:layout_height="180dp"
        android:layout_marginStart="8dp"
        android:layout_marginLeft="8dp"
        android:layout_marginEnd="8dp"
        android:layout_marginRight="8dp"
        android:background="@drawable/image_round_background"
        android:contentDescription="@null"
        android:padding="10dp"
        android:src="@drawable/unknown_image"
        android:tint="@color/colorPrimary"
        app:layout_constraintBottom_toBottomOf="@+id/image_view_blur"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/image_view_blur"
        app:layout_constraintVertical_bias="0.75" />
</android.support.constraint.ConstraintLayout>

xhdp Huawei hdpi samsung

1 Ответ

0 голосов
/ 09 мая 2019

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

...