![](/img/trans.png)
[英]Why won't a textView from a different layout file not properly run setText but textViews from activity_main will?
[英]My app layout is different from activity_main layout design
我正在尝试制作一个英制到公制转换应用程序,它运行良好,直到遇到Android模拟器问题为止。 模拟器中的布局完全搞砸了,我也不知道为什么。 http://imgur.com/a/IBOcs
编辑:
整个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>
发生问题是因为您正在使用约束布局,但没有为项目提供任何约束。 因此,每个项目都显示在(0,0)位置。
约束布局说明:
布局编辑器允许您将小部件放置在画布上的任何位置,并使用设计时属性(例如layout_editor_absoluteX)记录当前位置。这些属性在运行时不适用,因此,如果将布局推送到设备上,则可能会出现小部件与编辑器中显示的位置不同。 要解决此问题,请通过从边缘连接处拖动来确保小部件同时具有水平和垂直约束。
因此,要么分配x和y值,要么使用LinearLayout / RelativeLayout。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.