Android支持不同的屏幕尺寸错误

时间:2019-05-08 13:02:18

标签: android xml android-layout layout

在支持不同的屏幕尺寸时,我遇到了问题。无论我做什么,应用程序始终会选择xhdpi布局。我已经在两部智能手机上进行了测试。三星Core II和华为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 :(得分:0)

请检查您的布局文件夹。您的布局也显示在布局文件夹中,因此这就是在两个设备中加载相同布局的原因。