0

我正在尝试为 Android Studio 中的应用创建登录页面。该页面的 XML 代码是 -

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:background="@color/colorPrimary"
    tools:context=".LoginChoice">


    <Button
        android:id="@+id/userbtn"
        android:layout_width="100dp"
        android:layout_height="30dp"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="450dp"
        android:onClick="userloginIntent"
        android:adjustViewBounds="true"
        android:background="@drawable/user_login_button_small"
        app:strokeColor="@android:color/white" />

    <androidx.appcompat.widget.AppCompatButton
        android:id="@+id/driverbtn"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:textColor="@android:color/white"
        android:onClick="driverloginIntent"
        android:paddingHorizontal="10dp"
        android:text="@string/driver_login"
        android:background="@drawable/buttonbg1"
        android:layout_marginVertical="20dp"
        android:layout_below="@+id/userbtn"/>

</RelativeLayout>

这里的问题是Button,我正在使用的 s 在我的手机中运行应用程序时看起来比Design在 Android Studio 中运行的要低得多。这是它在 android studio 中的外观- 在此处输入图像描述

这是我在手机上运行应用程序时的屏幕截图- 在此处输入图像描述

为什么会发生这种情况,我能做些什么来解决它?

4

1 回答 1

1

在 Android Studio 中,您可以选择用于可视化您layout.xml的设备的设备,默认设备可能没有您的物理设备的尺寸。您可以更改它或添加设备定义以匹配您所需的设备。此外,您可以使用布局验证来查看更准确的设计预览。

请记住,您使用dp的是单位度量,而不是标准pixels

在此处输入图像描述

于 2021-03-10T14:23:35.193 回答