Android Studio中的layout_marginTop [英] layout_marginTop in Android Studio
问题描述
我正在尝试为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-autoxmlns:tools ="http://schemas.android.com/tools"android:background =" @ color/colorPrimary"工具:context =.LoginChoice".<按钮android:id ="@@ id/userbtn"android:layout_width =" 100dp"android:layout_height =" 30dp"android:layout_centerHorizontal ="true"android:layout_marginTop =" 450dp"android:onClick =" userloginIntentandroid:adjustViewBounds =" true"android:background =" @ drawable/user_login_button_small"app:strokeColor =" @android:color/white"/>< androidx.appcompat.widget.AppCompatButtonandroid: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
在手机中运行应用程序时的显示效果比在Android Studio中的 Design
区域中显示的要低得多.这是在android studio中的样子-
这是我在手机上运行该应用程序时的屏幕截图-
为什么会发生这种情况,我该怎么解决?
在Android Studio中,您可以选择用于可视化 layout.xml
的设备,默认设备可能不是具有与您的物理设备相同的尺寸.您可以更改它或添加设备定义以匹配所需的设备.另外,您可以使用
I am trying to create a login page for an app in Android Studio. The XML code for the page is -
<?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>
The problem here is that the Button
s that I am using, appear much lower on running the app in my phone than they do in the Design
area in Android Studio.
Here's how it looks in android studio-
And here is a screenshot of when I run the app on my phone-
Why is this happening and what can I do to fix it?
In Android Studio, you can choose the device that you are using to visualize your layout.xml
, the default device may not be have the dimensions as your physical device. You can change it or add a device definition to match your desired device. Also, you could use Layout Validation to see a more accurate preview of your design.
Remember that you are using dp
as a unit measure, not standard pixels
.
这篇关于Android Studio中的layout_marginTop的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!