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);