【发布时间】:2021-03-10 13:57:24
【问题描述】:
我正在尝试为 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>
这里的问题是,我正在使用的Buttons 在我的手机中运行应用程序时看起来比在 Android Studio 中的Design 区域中运行的要低得多。
这是它在 android studio 中的外观-
为什么会发生这种情况,我可以做些什么来解决它?
【问题讨论】:
-
你想达到什么目的?您将上边距设置为 userBtn = 450dp。该值会因设备的屏幕尺寸而异。
标签: android android-studio button layoutmargins