Android Studio在真实设备上的布局更改

Android Studio在真实设备上的布局更改,android,android-studio,layout,android-layout-editor,Android,Android Studio,Layout,Android Layout Editor,我对Android Studio的布局有问题。编辑器(XML文件)和仿真器(Nexus10)显示了右侧的布局。但如果我在我的华为Mediaped M5上运行该应用程序,布局会发生变化,所有内容都是混合的 模拟器和我的设备具有相同的分辨率(2560*1600) XML文件: <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/

我对Android Studio的布局有问题。编辑器(XML文件)和仿真器(Nexus10)显示了右侧的布局。但如果我在我的华为Mediaped M5上运行该应用程序,布局会发生变化,所有内容都是混合的

模拟器和我的设备具有相同的分辨率(2560*1600)

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=".MainActivity">

<Button
    android:id="@+id/button_fahrzeugsimulation"
    android:layout_width="461dp"
    android:layout_height="203dp"
    android:layout_alignParentStart="true"
    android:layout_alignParentTop="true"
    android:layout_marginStart="108dp"
    android:layout_marginTop="173dp"
    android:background="@android:color/holo_blue_dark"
    android:text="Fahrzeugsimulation"
    android:textColor="#ffffff"
    android:textSize="38sp"
    android:textStyle="bold" />

<Button
    android:id="@+id/button_uebungen"
    android:layout_width="457dp"
    android:layout_height="182dp"
    android:layout_alignParentBottom="true"
    android:layout_alignStart="@+id/button_fahrzeugsimulation"
    android:layout_marginBottom="106dp"
    android:background="@android:color/holo_blue_dark"
    android:text="Übungen"
    android:textColor="#ffffff"
    android:textSize="38sp"
    android:textStyle="bold" />

<Button
    android:id="@+id/button_Weiterbildungsangebot"
    android:layout_width="wrap_content"
    android:layout_height="207dp"
    android:layout_alignBottom="@+id/button_fahrzeugsimulation"
    android:layout_alignParentEnd="true"
    android:layout_marginEnd="107dp"
    android:background="@android:color/holo_blue_dark"
    android:text="Weiterbildungsangebot"
    android:textColor="#ffffff"
    android:textSize="38sp"
    android:textStyle="bold" />

<Button
    android:id="@+id/button_Unterlagen"
    android:layout_width="498dp"
    android:layout_height="185dp"
    android:layout_alignStart="@+id/button_Weiterbildungsangebot"
    android:layout_alignTop="@+id/button_uebungen"
    android:layout_marginStart="-6dp"
    android:layout_marginTop="-2dp"
    android:background="@android:color/holo_blue_dark"
    android:text="Unterlagen"
    android:textColor="#ffffff"
    android:textSize="38sp"
    android:textStyle="bold" />

<TextView
    android:id="@+id/textView_eMobility"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentStart="true"
    android:layout_alignParentTop="true"
    android:layout_marginStart="16dp"
    android:layout_marginTop="16dp"
    android:text="eMobility"
    android:textColor="@android:color/holo_blue_dark"
    android:textStyle="bold"
    android:textSize="64sp" />

<TextView
    android:id="@+id/textView_Lab"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignTop="@+id/textView_eMobility"
    android:layout_toEndOf="@+id/textView_eMobility"
    android:text="Lab"
    android:textColor="@android:color/holo_red_light"
    android:textStyle="bold"
    android:textSize="52sp" />


我认为问题在于真实设备的屏幕宽度与仿真器的屏幕宽度不同,因此您需要

要创建不同的布局,以支持屏幕宽度和高度以及每个布局中的设计

更改视图尺寸以适应屏幕


此文档将有助于:

您的测试分辨率与您尝试在设备上测试的设备不同的设备(华为Mediaped M5)

因此,您面临着这个问题。即使您在布局中使用marginstart,也会有一些静态值随设备的不同而变化

像这样的价值观:

android:layout_width="457dp"
android:layout_height="182dp"
android:layout_marginStart="108dp"
android:layout_marginTop="173dp"
在显示nexus10和华为Mediaped M5的链接下方检查设备屏幕尺寸


这是预览而不是xml文件不要为按钮定义绝对值-使用
线性布局
网格布局
表格布局
并使用权重。