Android/에러
Missing required view with ID
닉네임간편
2021. 12. 21. 01:26
1. 발생 원인
커스텀 뷰를 만들어서 사용할 때, 해당 커스텀 뷰를 다른 곳에서 사용할 때 바로 id를 사용하면 이 에러가 발생합니다.
즉, 예를 들어서 아래처럼 사용할 경우 위 에러가 발생합니다.
<com.mackduckcrew.mackduck.custom.CustomView
android:id="@+id/customview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:about_mackduck_image="@drawable/about_mackduck_people_sunny"
app:about_mackduck_position="IOS Developer"
app:about_mackduck_name="Tintin"/>
2. 해결 방법
커스텀 뷰는 다른 레이아웃 안에 포함시키고, 그 레이아웃에 ID 값을 할당해서 사용해야 합니다.
한 가지 예시로, 아래처럼 LinearLayout 으로 커스텀 뷰를 감싼 다음 사용하시면 됩니다.
<LinearLayout
android:id="@+id/about_mackduck_tintin"
android:layout_width="0dp"
android:layout_columnWeight="1"
android:layout_height="wrap_content"
android:orientation="vertical">
<com.mackduckcrew.mackduck.custom.CustomView
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:about_mackduck_image="@drawable/about_mackduck_people_sunny"
app:about_mackduck_position="IOS Developer"
app:about_mackduck_name="Tintin"/>
</LinearLayout>
728x90
반응형