[英]Why does my app look different on design mode and emulator?
I am programming an app and have custom design for my app, the problem is the ui looks perfect in design mode but in run-time mode (on emulator and real device) it looks different. 我正在为一个应用编程,并为我的应用进行了自定义设计,问题是用户界面在设计模式下看起来很完美,但是在运行时模式下(在仿真器和真实设备上)它看起来有所不同。 Any clue why???
任何线索为什么??? Thanks to everyone.
谢谢大家。
My accomplish it to make the ui in emulator look the same as in design mode. 我完成了这项工作,以使模拟器中的ui看起来与设计模式下的ui相同。
Here's some code: 这是一些代码:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
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"
android:orientation="vertical"
android:background="@drawable/bg"
android:weightSum="8">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight=".8">
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight=".8">
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:gravity="center"
android:layout_marginLeft="50sp"
android:layout_marginRight="50sp"
android:padding="4dp"
android:layout_weight=".8">
<Button
android:text="Start"
android:textColor="#0495d4"
android:textAllCaps="false"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/btnStart"
android:layout_gravity="center" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:gravity="center"
android:layout_marginLeft="50sp"
android:layout_marginRight="50sp"
android:padding="4dp"
android:layout_weight=".8">
<Button
android:text="Followings"
android:textColor="#0495d4"
android:textAllCaps="false"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/btnFollowings"
android:layout_gravity="center" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight=".8">
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:gravity="center"
android:layout_weight=".8"
android:orientation="horizontal"
android:weightSum="3">
<LinearLayout
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight=".2"/>
<LinearLayout
android:layout_width="0dp"
android:padding="2sp"
android:layout_height="fill_parent"
android:layout_weight="2.6">
<EditText
android:hint="Pin Code"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:textSize="16dp"
android:textColor="@android:color/white"
android:fontFamily="sans-serif-medium"
android:textColorHint="@android:color/white"
android:backgroundTint="@android:color/white"
android:id="@+id/txtPinCode" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight=".2"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:gravity="center"
android:layout_weight=".8"
android:orientation="horizontal"
android:weightSum="3">
<LinearLayout
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight=".8"/>
<LinearLayout
android:layout_width="0dp"
android:padding="10sp"
android:gravity="center"
android:layout_height="fill_parent"
android:layout_weight="1.4">
<Button
android:text="Verify Pin"
android:textColor="#0495d4"
android:textAllCaps="false"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/btnSavePin"
android:layout_gravity="center" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight=".8"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="2.4">
</LinearLayout>
</LinearLayout>
The reason why the designs look different is that the emulator's screen configuration is different to that which is used to render the design preview. 设计看起来不同的原因是仿真器的屏幕配置与用于呈现设计预览的屏幕配置不同。
In the dropdown (see screenshot 1 ) of the layout editor try to find a configuration that matches your emulated device both in dimension and dpi. 在布局编辑器的下拉列表中(请参见屏幕截图1 ),尝试找到在尺寸和dpi上都与您的仿真设备匹配的配置。 That way the preview will be more accurate.
这样,预览将更加准确。
To find out which screen configuration your emulator has just go to the device manager (screenshot 2 ) and refer to the resolution column. 要找出您的仿真器具有哪种屏幕配置,只需转到设备管理器(屏幕截图2 ),然后参考分辨率列。
On different devices (device emulators) and on different versions of android different values of standard styles (textView, input field and so on). 在不同的设备(设备仿真器)和不同版本的android上,标准样式的不同值(textView,输入字段等)。 The designer shows everything verbatim, the device widgets are mixed with styles from the standard android library (a specific version)
设计师逐字显示所有内容,设备小部件与标准android库(特定版本)中的样式混合在一起
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.