Java 我的应用程序布局不同于活动\ U主布局设计
我正在尝试制作一个从英制到公制转换的应用程序,这很好,直到我在Android模拟器上遇到问题。模拟器的布局完全搞砸了,我不知道为什么 编辑: 整个activity_main.xml代码:Java 我的应用程序布局不同于活动\ U主布局设计,java,android,virtual-device-manager,Java,Android,Virtual Device Manager,我正在尝试制作一个从英制到公制转换的应用程序,这很好,直到我在Android模拟器上遇到问题。模拟器的布局完全搞砸了,我不知道为什么 编辑: 整个activity_main.xml代码: <?xml version="1.0" encoding="utf-8"?> <android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 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"
tools:context="com.example.daniel.converter.MainActivity"
tools:layout_editor_absoluteY="73dp"
tools:layout_editor_absoluteX="0dp">
<TextView
android:id="@+id/textViewMPH"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="MPH"
tools:layout_editor_absoluteX="55dp"
tools:layout_editor_absoluteY="90dp" />
<EditText
android:id="@+id/editTextMPH"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="number"
tools:layout_editor_absoluteX="85dp"
tools:layout_editor_absoluteY="77dp" />
<TextView
android:id="@+id/textViewTO"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="To"
tools:layout_editor_absoluteX="55dp"
tools:layout_editor_absoluteY="132dp" />
<TextView
android:id="@+id/textViewKMH"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="KMH"
tools:layout_editor_absoluteX="55dp"
tools:layout_editor_absoluteY="168dp" />
<EditText
android:id="@+id/editTextKMH"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="number"
tools:layout_editor_absoluteX="85dp"
tools:layout_editor_absoluteY="156dp" />
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Convert!"
tools:layout_editor_absoluteX="146dp"
tools:layout_editor_absoluteY="229dp" />
</android.support.constraint.ConstraintLayout>
发生此问题的原因是您正在使用约束布局,但尚未为项目提供任何约束。因此,每个项目都显示在0,0位置 合同布局说明: 布局编辑器允许您将小部件放置在画布上的任何位置,并使用设计时属性(如布局编辑器)记录当前位置。这些属性不会在运行时应用,因此如果在设备上推送布局,小部件可能会显示在不同于编辑器中显示的位置。要解决此问题,请通过从边缘连接拖动来确保小部件同时具有水平和垂直约束
因此,要么指定x和y值,要么使用LinearLayout/RelativeLayout。您好,请看一看,在当前状态下,这个问题是无法回答的。您使用的是绝对布局。尝试相对布局