adjustPan 是 Android 中 NestedScrollView 的一个属性,它的作用是在展开抽屉时,确保当前选中的子项可见。当你在嵌套滚动视图中使用 adjustPan 时,它会在打开抽屉时调整父滚动视图的位置,以便当前选中的子项始终可见。
在嵌套滚动视图中使用 adjustPan 的表现如下:
adjustPan 会使父滚动视图向上移动,以确保当前选中的子项可见。adjustPan 不会对父滚动视图进行任何操作。adjustPan 会使父滚动视图向上移动,以确保当前选中的子项可见。要在嵌套滚动视图中使用 adjustPan,你可以在 XML 布局文件中设置 android:windowSoftInputMode="adjustPan" 属性,或者在代码中调用 setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN) 方法。例如:
<androidx.core.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:windowSoftInputMode="adjustPan"> <!-- Your nested content here --> </androidx.core.widget.NestedScrollView> 或者在 Java 代码中:
NestedScrollView nestedScrollView = findViewById(R.id.nested_scroll_view); nestedScrollView.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);