Android studio在xml中无法使用NestedScrollView
时间: 2023-12-08 13:03:30 浏览: 41
NestedScrollView 是一个支持嵌套滚动的ScrollView,它可以在滚动子 View 时同步滚动父 View。在 Android Studio 中使用 NestedScrollView 需要在 app/build.gradle 文件中添加如下依赖:
```
implementation 'com.android.support:design:28.0.0'
```
然后在 XML 布局文件中使用 NestedScrollView 即可,如下所示:
```
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- 嵌套滚动的子 View -->
</android.support.v4.widget.NestedScrollView>
```
需要注意的是,如果你使用的是 androidx 库,那么需要使用如下依赖:
```
implementation 'com.google.android.material:material:1.0.0'
```
并且在 XML 布局文件中使用 androidx 包下的 NestedScrollView:
```
<com.google.android.material.nestedscrollview.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- 嵌套滚动的子 View -->
</com.google.android.material.nestedscrollview.NestedScrollView>
```