본문 바로가기
Android

[안드로이드] Databinding으로 View의 visibility 설정하기

by JongSeok 2023. 7. 18.

Databinding을 이용해 xml 파일에서 뷰의 visibility 속성을 지정하려는 이리저리 바꿔보아도 빨간 줄이 사라지지 않습니다..

무시하고 그냥 빌드를 했더니 이런 오류 문구가 뜨더군요.

Could not find identifier 'View'.
Check that the identifier is spelled correctly, and that no <import> or <variable> tags are missing.

 

원인은 <data></data> 태그에 View가 import 되어 있지 않은 이유였습니다.

해결방법

<data>
    <import type="android.view.View"/>
    ...
</data>

...
<com.rey.material.widget.FrameLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:visibility="@{!viewmodel.thumbnail.empty ? View.VISIBLE : View.GONE}">

 

728x90
반응형