理想效果:

實際效果:

原因:因為文件中一個控件的約束屬性寫錯了
這個屬性是 app:layout_constraintLeft_toLeftOf="@id/oa_setting_group_tv_add"
寫成了自己在自己左邊了。
<TextView
android:id="@+id/oa_setting_group_tv_add"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/dp_10"
android:text="新增考勤組"
android:textColor="@color/oa_color"
android:textSize="@dimen/sp_16"
app:layout_constraintBottom_toBottomOf="@id/oa_setting_group_background_add"
app:layout_constraintLeft_toLeftOf="@id/oa_setting_group_tv_add"
app:layout_constraintTop_toTopOf="@id/oa_setting_group_background_add" />
如何發現:逐個排查
-
首先將第一個控件放在了另一個已經在使用的布局里,正常顯示;
-
在使用 tools-> XML Action->validate 檢查無果后。
-
重新建立個文件,逐個控件,逐個屬性的寫,這時完全不 care 原文件。
-
因為這次比較仔細,故理想的樣子直接就出來了
-
對照兩個文件,發現有一個屬性寫錯了!!!
如何修復:改回來
總結:實時預覽!
ConstraintLayout 一個控件的疏忽就是滿盤皆輸。
打開預覽,實時注意效果。實在太着急最次也要一個控件一預覽。否則太難找了。
