問題発生
状態:解決済
閲覧数:3,054
投稿日:2018-05-06
更新日:2018-05-06
ウィジェットを配置できない
ボタンを選択
・ドラッグして配置しようとするも、×印が表示され続けるためどこにも配置できない
エラー原因
「layout/activity_main.xml」に余計なコードが含まれているため
解決方法
「layout/activity_main.xml」に含まれている余計なコードを削除
実際に遭遇した例
問題発生
Designプレビューでボタンをドラッグ配置できない
問題コード
▼layout/activity_main.xml
<?xml version= "1.0" encoding= "utf-8" ?> <android.support.constraint.ConstraintLayout xmlns:android= "http://schemas.android.com/apk/res/android" android:layout_width= "match_parent" android:layout_height= "match_parent" tools:context= ".MainActivity" tools:layout_editor_absoluteY= "81dp" > <TextView android:id= "@+id/textView" android:layout_width= "wrap_content" android:layout_height= "wrap_content" android:layout_marginEnd= "132dp" android:layout_marginTop= "16dp" android:text= "@string/first" android:textSize= "30sp" app:layout_constraintEnd_toEndOf= "parent" app:layout_constraintTop_toTopOf= "parent" /> </android.support.constraint.ConstraintLayout> |
エラー対応
正常動作している別プロジェクトの該当ソースコードと比較して、怪しいところを探す
エラー発生箇所を特定
下記を削除
▼layout/activity_main.xml
tools:layout_editor_absoluteY="81dp |
修正後のコード
▼layout/activity_main.xml
<?xml version= "1.0" encoding= "utf-8" ?> <android.support.constraint.ConstraintLayout xmlns:android= "http://schemas.android.com/apk/res/android" android:layout_width= "match_parent" android:layout_height= "match_parent" tools:context= ".MainActivity" > <TextView android:id= "@+id/textView" android:layout_width= "wrap_content" android:layout_height= "wrap_content" android:layout_marginEnd= "132dp" android:layout_marginTop= "16dp" android:text= "@string/first" android:textSize= "30sp" app:layout_constraintEnd_toEndOf= "parent" app:layout_constraintTop_toTopOf= "parent" /> </android.support.constraint.ConstraintLayout> |