如果使用物理设备或 Bluestacks 模拟器,布局显示会非常不同

Posted

技术标签:

【中文标题】如果使用物理设备或 Bluestacks 模拟器,布局显示会非常不同【英文标题】:Layout displays very differently if using physical device or Bluestacks emulator 【发布时间】:2017-08-21 06:41:48 【问题描述】:

最近一段时间,我一直在使用 android Studio 和 BlueStacks 开发一个 Android 应用,结果一切都很好。但是,当我尝试在我的物理设备上运行该应用程序时,所有内容的显示方式都大不相同。

在 Bluestacks 仿真上一切看起来都很棒(手机设置为纵向模式),但在实体手机上,一切看起来都被挤压在一起(好像手机的分辨率很小)。

有人见过类似的吗?这只是我的物理设备的问题吗?

Here is an image of what the login page looks like in Emulator

And here's the physical device Screenshot

这是我的 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:id="@+id/activity_login"
android:layout_
android:layout_
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:background="#ff292929"
tools:context="com.socialivemusic.socialivemusic.LoginActivity">
<ImageView
    android:layout_
    android:layout_
    app:srcCompat="@drawable/socialogo"
    android:id="@+id/imageView"
    android:layout_gravity="center"
    android:layout_alignParentTop="true"
    android:layout_marginBottom="50dp"
    android:layout_centerHorizontal="true"/>

<EditText
    android:layout_
    android:layout_
    android:inputType="textEmailAddress"
    android:layout_below="@+id/imageView"
    android:layout_marginBottom="50dp"
    android:ems="10"
    android:id="@+id/loginEmail"
    android:background="#ffffffff"
    android:hint="Enter Email"
    android:textColorHint="#ff434343"
    android:textColor="#ff292929"
    android:textSize="30sp"/>

<EditText
    android:layout_
    android:layout_
    android:inputType="textPassword"
    android:layout_below="@id/loginEmail"
    android:ems="10"
    android:id="@+id/loginPw"
    android:background="#ffffffff"
    android:hint="Enter Password"
    android:textColorHint="#ff434343"
    android:textColor="#ff292929"
    android:layout_marginBottom="@dimen/activity_horizontal_margin"
    android:textSize="30sp"/>

<Button
    android:text="LOGIN"
    android:textColor="#ffffffff"
    android:layout_
    android:layout_
    android:layout_marginTop="@dimen/activity_horizontal_margin"
    android:id="@+id/loginButton"
    android:background="#08AE9E"
    android:layout_below="@+id/loginPw"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true"
    android:layout_alignParentRight="true"
    android:layout_alignParentEnd="true"
    android:textSize="30sp"/>

<TextView
    android:text="I fogot my Password"
    android:textColor="#ffffffff"
    android:layout_
    android:layout_
    android:layout_below="@+id/loginButton"
    android:layout_marginTop="@dimen/activity_horizontal_margin"
    android:layout_centerHorizontal="true"
    android:id="@+id/toPwRedo"
    android:textSize="20sp"/>

<Button
    android:text="REGISTER"
    android:textColor="#ffffff"
    android:layout_
    android:layout_
    android:layout_alignParentBottom="true"
    android:id="@+id/toRegister"
    android:layout_alignParentRight="true"
    android:layout_alignParentEnd="true"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true"
    android:background="#ff434343"
    android:textSize="30sp"/>
</RelativeLayout>

【问题讨论】:

这不是问题。您的 bluestack 预览更像是大屏幕手机,而您的物理设备尺寸更小。根据不同的屏幕尺寸来纠正这种设计。 【参考方案1】:

这是因为您的设备和模拟器的尺寸不同。当您在 dp 中给出尺寸时,您应该将这些尺寸放在 dimens.xml、dimens.xml (w600dp)、dimens.xml (w720dp)、dimens.xml (w820dp) 等文件中,以满足不同密度的设备和决议。

例如: dimens.xml-&lt;dimen name="d2dp"&gt;2dp&lt;/dimen&gt;, dimens.xml (w600dp)-&lt;dimen name="d2dp"&gt;3dp&lt;/dimen&gt;, dimens.xml (w720dp)-&lt;dimen name="d2dp"&gt;4dp&lt;/dimen&gt;

然后在你的布局中使用它作为android:layout_height="@dimen/d2dp"

了解如何处理不同尺寸的屏幕。

【讨论】:

啊,好的,非常感谢您提供的信息!我会花一天时间整理各个维度! 当然可以,您能否为我指明一些关于如何进行此操作的好教程的方向?只是想确保我做的一切都正确! 对不起,我目前没有有用的链接,但我为你做了一些研究,我觉得你应该阅读最小宽度的概念。 This & This 会给你一个简短的想法。休息你将不得不研究。 This 是 *** 上解释如何使用维度的答案。

以上是关于如果使用物理设备或 Bluestacks 模拟器,布局显示会非常不同的主要内容,如果未能解决你的问题,请参考以下文章

如何将 VS Code 中的 Flutter 与 BlueStacks 4 模拟器连接起来?

iOS 模拟器或物理设备未收到 FCM 数据消息

MoSync IDE:如何在 Bluestacks 中运行 apk?

如何使用adb与Memu / Bluestacks / Nox App Player等模拟器

模拟器或物理设备上的“未安装应用程序”android? [复制]

swift 检查应用程序是否在模拟器或物理iOS设备上运行