[英]Android: Recyclerview not resizing when softinput keyboard appears
我有一個包含片段的活動,並且該片段包含一個自定義視圖。 customview 包含一個edittext,在它的正下方是一個高度為match_parent 的recyclerview。 當用戶關注edittext時,會出現一個軟輸入鍵盤。不幸的是,這個鍵盤隱藏了它下面的一半recyclerview。 我希望 recyclerview 調整到屏幕的剩余可見高度(在edittext下),以便列表中的項目不會被鍵盤隱藏。
我已經嘗試為清單中的活動設置adjustresize,但它沒有效果:
android:windowSoftInputMode="adjustResize"
我嘗試將我的應用程序主題設置為基本主題(以防我的自定義主題中的某些內容導致問題) - 沒有效果:
android:theme="@style/Theme.AppCompat.NoActionBar"
我已經檢查以確保層次結構的任何地方都沒有框架布局到必須調整大小的視圖(我讀了一個可能是問題的 SO 線程) - 沒有。
我檢查了活動、片段、自定義視圖和連接的每個適配器,以確保我沒有在任何地方調用 getWindow(我沒有)。
customview 在運行時從viewstub 膨脹。 這可能有聯系嗎?
編輯:
父母的內容:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/parent_root"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
...
<ViewStub
android:id="@+id/viewstub_outername"
android:layout="@layout/viewstub_thatIneed"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
</RelativeLayout>
視圖的內容:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/viewstub_root"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:background="@android:color/white"
>
<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerview1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="20dp"
android:visibility="invisible"
/>
<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerview2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="20dp"
android:visibility="invisible"
/>
</RelativeLayout>
如此顯示鍵盤:
public static void showSoftKeyboard(Activity activity) {
View view = activity.getCurrentFocus();
InputMethodManager inputManager = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE);
inputManager.showSoftInput(view, InputMethodManager.SHOW_IMPLICIT);
}
不要在清單文件中做任何事情。 只需使用
((LinearLayoutManager)recyclerView.getLayoutManager()).setStackFromEnd(true);
這將負責 recyclerview 調整大小。
window.decorView.setOnApplyWindowInsetsListener { view, insets ->
val insetsCompat = toWindowInsetsCompat(insets, view)
mainNavigation.isGone = insetsCompat.isVisible(ime())
view.onApplyWindowInsets(insets)
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.