Android
[Android-java] Unable to start activity ComponentInfo{com.example.health/com.example.starBooks.MainActivity}: android.view.InflateException: Binary XML file line #70: ScrollView can host only one direct child 에러 해결
기시미
2021. 9. 25. 02:53
안녕하세요
개발 중에 만난 에러를 적어보려고 합니다.
에러 내용 : Unable to start activity ComponentInfo{com.example.health/com.example.starBooks.MainActivity}: android.view.InflateException: Binary XML file line #72: ScrollView can host only one direct child
ScrollView에는 하나의 레이아웃만 존재해야하는데 아래 코드와 같이 1개 이상이 있을 경우 해당 에러가 발생합니다.
<androidx.core.widget.NestedScrollView
android:id="@+id/scroll_view"
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
app:adapter="@{mainAdapter}"/>
<ProgressBar
android:id="@+id/progress_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</androidx.core.widget.NestedScrollView>
해결방법
아래 코드와 같이 하나의 레이아웃으로 묶어주시면 됩니다.
<androidx.core.widget.NestedScrollView
android:id="@+id/scroll_view"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
app:adapter="@{mainAdapter}"/>
<ProgressBar
android:id="@+id/progress_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
</androidx.core.widget.NestedScrollView>
