본문 바로가기
개발/kotlin

[Kotlin] tools:ignore="UselessParent"

by 1인용 놀이터 2025. 2. 3.
728x90
반응형

로또번호 추첨 어플 내에,

버튼 클릭 시 랜덤 번호 추가를 하려고 layout과 textview 동적 생성 작업 중 xml 의 layout에서 warnning이 떴고,

android studio에서 추천해 주는 걸로 하려니 

 

tools:ignore="UselessParent"

 

layout 내 위의 내용이 추가 됨. 그리고 layout 안보임.

 

추천 문구와 함께 적혀 있는내용을 보니, 해당 layout은 자식은 있으면서 형제 요소가 없고, scroll view나 root layout도 아니고 배경도 없으니,굳이 이 layout이 필요하겠냐

이 layout이 갖고 있는 자식을 부모 layout으로 옮겨서 효율적인 레이아웃 계층으로 만들자.

뭐 대충 이런식으로 적혀 있음.

 

<androidx.constraintlayout.widget.ConstraintLayout>
	<LinearLayout> // main layout
		<LinearLayout> // 첫 번째 로또번호 layout
			<TextView></TextView>
			<TextView></TextView>
		</LinearLayout>
    </LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>

  

대충 xml 구조는 저런 상태 였음.

"첫 번째 로또번호 layout" 에서 warnning이 나타난 거였음.

 

이전에도 layout 에 대해 이것저것 만들어 볼 때 같은 warnning을 봤던 기억에 정리 해놓음.

생각보다 간단했음.

main layout 내에 button을 하나 추가 함.

즉, 형제 요소를 추가 했음.

 

error가 아니라 굳이 필요 없는 것 같은 layout 이 하나 더 있으니 android studio 내에서

" 이거 필요 없을거 같은데 ? "  라고 알려주는 것 같음. 

<androidx.constraintlayout.widget.ConstraintLayout>
	<LinearLayout> // main layout
		<LinearLayout> // 첫 번째 로또번호 layout
			<TextView></TextView>
			<TextView></TextView>
		</LinearLayout>
		<Button>
		</Button>
    </LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>

 

 

728x90
반응형