【发布时间】:2020-08-14 21:46:21
【问题描述】:
当我在 android 模拟器 (Nexus 5X) 中运行我的 android 项目时,它会显示我设计的正确布局。但是如果我在硬件设备(三星 Galaxy J2 Prime)中运行项目,它会显示不同的输出。(边距不完全正确在硬件设备中它粘在底部,请查看底部的边距) 1 - 硬件设备的输出 2 - 模拟器的输出
这是布局的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>
【问题讨论】:
-
这可能是由于设备和模拟器上的像素密度造成的。
-
那么如果我用android studio开发android应用程序,它不适合所有的android设备吗?我应该为不同的设备使用不同的格式吗?
-
是和否。您可以配置您的 UI,也可以选择为不同的显示进行布局。使用 ConstraintLayout 而不是线性或相对。 ??????
标签: android xml android-studio android-layout android-emulator