简体   繁体   English

我的应用布局与activity_main布局设计不同

[英]My app layout is different from activity_main layout design

I'm trying to make a imperial to metric conversion app, which is going fine, until I ran into problems with the Android Emulator. 我正在尝试制作一个英制到公制转换应用程序,它运行良好,直到遇到Android模拟器问题为止。 The layout is totally screwed up in the Emulator, and I have no idea why. 模拟器中的布局完全搞砸了,我也不知道为什么。 http://imgur.com/a/IBOcs http://imgur.com/a/IBOcs

EDIT: 编辑:

The whole activity_main.xml code: 整个activity_main.xml代码:

<?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>

Issue is happening because you are using constraint layout but you have not provided any constraints for your items. 发生问题是因为您正在使用约束布局,但没有为项目提供任何约束。 Thus, every item is shown at (0,0) position. 因此,每个项目都显示在(0,0)位置。

Contraint Layout description: 约束布局说明:

The layout editor allows you to place widgets anywhere on the canvas, and it records the current position with designtime attributes (such as layout_editor_absoluteX.) These attributes are not applied at runtime, so if you push your layout on a device, the widgets may appear in a different location than shown in the editor. 布局编辑器允许您将小部件放置在画布上的任何位置,并使用设计时属性(例如layout_editor_absoluteX)记录当前位置。这些属性在运行时不适用,因此,如果将布局推送到设备上,则可能会出现小部件与编辑器中显示的位置不同。 To fix this, make sure a widget has both horizontal and vertical constraints by dragging from the edge connections. 要解决此问题,请通过从边缘连接处拖动来确保小部件同时具有水平和垂直约束。

So either assign x and y values or use LinearLayout/RelativeLayout. 因此,要么分配x和y值,要么使用LinearLayout / RelativeLayout。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 为什么来自不同布局文件的 textView 不能正确运行 setText 但来自 activity_main 的 textViews 会? - Why won't a textView from a different layout file not properly run setText but textViews from activity_main will? Android Studio框架布局未显示在activity_main中 - Android studio frame layout not showing up in activity_main Toast未显示在activity_main中/意图未切换activites /布局 - Toast not displaying in activity_main / Intent not switching activites/ layout 二进制 XML 文件第 18 行在 mypackage:layout/activity_main: Error inflating class androidx.fragment.app.FragmentContainerView - Binary XML file line #18 in mypackage:layout/activity_main: Error inflating class androidx.fragment.app.FragmentContainerView 如何在布局 activity_main(sw320dp) 中调用? - How do I call inside the layout activity_main(sw320dp)? #20 在 com.example.hellocompat:layout/activity_main: 错误充气 class TextView .....在 ZC31FCD103614EC19CA88 - #20 in com.example.hellocompat:layout/activity_main: Error inflating class TextView .....in android 如何在与 activity_main 不同的活动中从 SQLite 访问数据? - How to access data from SQLite in different activity than activity_main? activity_main错误 - activity_main error 错误:com.example.myfragment:layout/activity_main 中的二进制 XML 文件第 9 行。 - Error: Binary XML file line #9 in com.example.myfragment:layout/activity_main: Error inflating class fragment 如何根据 activity_main 中编辑文本中的文本更改片段中的 imageview 图像 - How can I change the imageview image in a fragment based on the text in a edittext from my activity_main
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM