개발(Android)/issues

[Android Studio] Warning:(숫자, 숫자) This tag and its children can be replaced by one `<TextView/>` and a compound drawable

shinyelee 2022. 8. 5. 18:20

[안드로이드 스튜디오] 이 태그(뷰)와 자식(뷰)들은 하나의 <텍스트뷰/>와 복합 드로어블로 대체될 수 있음

문제

레이아웃을 대충 이렇게 짜고 커밋 하려는데

                <!-- 아이콘 -->
                <ImageView
                    android:layout_width="120dp"
                    android:layout_height="120dp"
                    android:layout_marginHorizontal="15dp"
                    android:layout_gravity="center"
                    android:contentDescription="@string/web"
                    android:src="@drawable/web112" />

                <!-- 카테고리명 -->
                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="40dp"
                    android:gravity="center"
                    android:text="@string/web"
                    android:textSize="30sp" />

이런 경고가 떠서 구글링 해봄.


해결 방법

사실 error와 달리 warning은 안 고친다고 큰 문제가 나타나는 건 아니지만 효율성을 위해 코드를 수정하자.
이미지뷰를 통째로 지우고, 텍스트뷰에 코드 한 줄만 추가하면 된다.

                <!-- 카테고리 -->
                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:gravity="center"
                    android:text="@string/web"
                    android:textSize="30sp"
                    app:drawableTopCompat="@drawable/web112" />

참고

 

[Anroid] TextView, IamgeView 합체!!!! - This tag and its childer can be replaced by one <TextView/> and a compound drawable le

This tag and its childer can be replaced by one <TextView/> and a compound drawable less......

blog.naver.com

반응형