본문으로 바로가기
반응형


처음 안드로이드 스튜디오를 키고 버튼과 라벨을 추가했는데 오류가 뜬다. 그래서 해결법을 찾았다.


여기 마법봉같이 생긴 걸 클릭하면 된다. 왜인지는 모르겠지만 해결이 된다.
Infer Constraints라고 하는 기능인데 레이아웃을 정리해주는 것 같다.


처음 안드로이드 스튜디오를 키고 버튼과 라벨을 추가했는데 오류가 뜬다. 그래서 해결법을 찾았다.


여기 마법봉같이 생긴 걸 클릭하면 된다. 왜인지는 모르겠지만 해결이 된다.
Infer Constraints라고 하는 기능인데 레이아웃을 정리해주는 것 같다.

=== 추가 설명 ===

이유는 ConstraintLayout의 사용에 있다.

아래 사진은 디자이너 화면과 XML 코드이다.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Button1"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.145"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.374" />
 
    <Button
        android:id="@+id/button2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="235dp"
        android:layout_marginEnd="172dp"
        android:layout_marginRight="172dp"
        android:layout_marginBottom="392dp"
        android:text="Button2"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toEndOf="@+id/button1"
        app:layout_constraintTop_toTopOf="parent" />
 
    <Button
        android:id="@+id/button3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="button3"
        tools:layout_editor_absoluteX="47dp"
        tools:layout_editor_absoluteY="168dp" />
cs

Button1과 Button2는 Layout탭에서 따로 위치를 정해주었기 때문에 XML파일에 위치가 정의되어 있지만, Button3는 생성만 했기 때문에 위치가 정의되지 않았다.

즉 겉보기론 위치가 정해진 것처럼 보이지만, 실제론 위치가 정의되지 않아 에러를 뿜어내는 것이다.

missing constraints in constraintlayout이 발생하는 이유는 위치가 정의되지 않아서이다. 그럼 위치를 정해주면 되는데, 이를 자동으로 정해주는 것이 앞서 말했던 Infer Constraints와 Autoconnect이다.

Infer Constraints는 생성한 위젯의 위치를 자동으로 정해주는 기능이고, Autoconnect는 위젯을 생성하면 그 위젯의 위치를 자동으로 정해주는 기능이다.


반응형

'Study > Android' 카테고리의 다른 글

[Android] Infer Constraints가 뭘까?  (0) 2019.06.25