为什么android仿真器和硬件设备中的android项目输出不同

为什么android仿真器和硬件设备中的android项目输出不同,android,xml,android-studio,android-layout,android-emulator,Android,Xml,Android Studio,Android Layout,Android Emulator,当我在android emulator(Nexus 5X)中运行我的android项目时,它显示了我设计的正确布局。但是如果我在硬件设备中运行该项目(三星Galaxy J2 Prime),它会显示不同的输出。(在硬件设备中,边距并不完全正确,它会粘在底部,请参见底部的边距) -硬件设备输出 -仿真器输出 这是布局的xml代码 <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://

当我在android emulator(Nexus 5X)中运行我的android项目时,它显示了我设计的正确布局。但是如果我在硬件设备中运行该项目(三星Galaxy J2 Prime),它会显示不同的输出。(在硬件设备中,边距并不完全正确,它会粘在底部,请参见底部的边距) -硬件设备输出 -仿真器输出

这是布局的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"
    android:background="@drawable/background"
    tools:context=".OrderStatus">


    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

        <androidx.recyclerview.widget.RecyclerView
            android:id="@+id/listOrders"
            android:background="@android:color/transparent"
            android:layout_width="match_parent"
            android:layout_height="550dp">


        </androidx.recyclerview.widget.RecyclerView>

        <androidx.recyclerview.widget.RecyclerView
            android:id="@+id/listCalls"
            android:background="@android:color/transparent"
            android:layout_width="match_parent"
            android:layout_height="100dp">


        </androidx.recyclerview.widget.RecyclerView>


    </LinearLayout>


</RelativeLayout>

要完成此工作,请执行以下操作:

  • 将recyclerView的大小类型从dp(密度像素)更改为sp(可缩放像素)

    xmlns:tools=”http://schemas.android.com/tools" android:layout\u width=“匹配父项” android:layout\u height=“match\u parent” android:background=“@drawable/background” 工具:context=“.OrderStatus”>

    
    


布局缩放比例的变化也因设备而异。

要完成此工作,请执行以下操作:

  • 将recyclerView的大小类型从dp(密度像素)更改为sp(可缩放像素)

    xmlns:tools=”http://schemas.android.com/tools" android:layout\u width=“匹配父项” android:layout\u height=“match\u parent” android:background=“@drawable/background” 工具:context=“.OrderStatus”>

    
    


布局比例的变化也因设备而异。

如果希望在不同的设备中有协调的布局,请不要使用dp大小。这取决于手机的大小。最好使用约束布局。请参阅我对这个问题的回答,作为使用约束布局的示例:

如果您希望在不同的设备中有协调的布局,请不要使用dp大小。这取决于手机的大小。最好使用约束布局。以我对这个问题的回答作为使用约束布局的示例:

这可能是由于设备和模拟器上的像素密度造成的。因此,如果我使用android studio开发android应用程序,它是否不适合所有android设备?我应该为不同的设备使用不同的格式吗?是和否。你可以配置你的用户界面,也可以为不同的显示设置布局。使用ConstraintLayout而不是线性或相对。这可能是因为设备和模拟器上的像素密度。所以,如果我用android studio开发android应用程序,它不适合所有android设备吗?我应该为不同的设备使用不同的格式吗?是和否。你可以配置你的用户界面,也可以为不同的显示设置布局。使用ConstraintLayout而不是线性或相对。
<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <androidx.recyclerview.widget.RecyclerView
        android:id="@+id/listOrders"
        android:background="@android:color/transparent"
        android:layout_width="match_parent"
        android:layout_height="550sp">


    </androidx.recyclerview.widget.RecyclerView>

    <androidx.recyclerview.widget.RecyclerView
        android:id="@+id/listCalls"
        android:background="@android:color/transparent"
        android:layout_width="match_parent"
        android:layout_height="100sp">


    </androidx.recyclerview.widget.RecyclerView>


</LinearLayout>