[英]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.