首页 > 解决方案 > XML 布局与模拟器不同

问题描述

我已经花了 4 个小时来解决这个问题,但我无法解决它请任何帮助将不胜感激。当我更新我的 android 工作室时,这个问题停留在我的 android 工作室中。我正在使用 android studio 最新版本 3.2.1。

<?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=".View.First_Screen">

    <ImageView
        android:id="@+id/firstScreen_image"
        android:layout_width="match_parent"
        android:layout_height="350dp"
        android:layout_alignParentTop="true"
        android:layout_marginTop="0dp"
        android:background="@drawable/snap"
        android:src="@drawable/black_transparent" />

    <LinearLayout
        android:id="@+id/firstScreen_buttonLayout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/firstScreen_image"
        android:layout_marginTop="38dp"
        android:orientation="horizontal"
        android:weightSum="1">

        <Button
            android:id="@+id/firstScreen_login"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="5dp"
            android:layout_marginRight="2dp"
            android:layout_weight="0.5"
            android:background="@drawable/button_background"
            android:text="Login" />

        <Button
            android:id="@+id/firstScreen_register"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="2dp"
            android:layout_marginRight="5dp"
            android:layout_weight="0.5"
            android:background="@drawable/button_background"
            android:text="register" />

    </LinearLayout>

    <TextView
        android:id="@+id/firstScreen_connectDriver"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/firstScreen_buttonLayout"
        android:layout_marginLeft="5dp"
        android:layout_marginTop="32dp"
        android:text="Or be a captain of uber"
        android:textColor="#311B92"
        android:textSize="18dp"
        android:textStyle="bold" />


</RelativeLayout>

这是附加的图像,您可以在其中看到两种设备上的布局差异

标签: androidxml

解决方案


首先,我想确认您使用的是哪个模拟器,它是 nexus 4 还是其他模拟器,因为在预览中您的屏幕被选择为 nexus 4,并且视图显示的设备具有与 nexus 4 相同的像素密度和分辨率,接下来,您使用 id -“firstScreen_image”为 ImageView 提供了一个固定的 dp 高度。对于不同的设备,固定高度(即 350dp)的行为会有所不同。那么下一个问题是你希望你的屏幕是什么样的,我能提供什么帮助?


推荐阅读