我有一个包含片段和自定义视图的活动。自定义视图中包含一个edittext,直接下方是一个高度为match_parent的recyclerview。当用户在edittext上获得焦点时,会出现一个软输入键盘。不幸的是,这个键盘把recyclerview的一半隐藏了起来。我希望recyclerview可以调整大小以适应屏幕上剩余可见的高度(在edittext下方),以便列表中的项目不会被键盘遮挡。
我已尝试在清单文件中将adjustresize设置为活动,但没有效果:
我已检查了整个层次结构并没有发现任何Framelayouts与需要调整大小的视图相关(我在 Stack Overflow 上读到过可能会存在问题的讨论),因此这方面问题排除。
我已检查了活动、片段、自定义视图和每个连接的适配器,以确保没有在任何地方调用getWindow(我没有调用)。
自定义视图是在运行时从ViewStub中填充的。这是否有关联?
编辑:
父元素的内容:
如下所示显示键盘:
我已尝试在清单文件中将adjustresize设置为活动,但没有效果:
android:windowSoftInputMode="adjustResize"
我尝试将应用主题设置为基本主题(以防我的自定义主题导致问题)- 没有效果:
android:theme="@style/Theme.AppCompat.NoActionBar"
我已检查了整个层次结构并没有发现任何Framelayouts与需要调整大小的视图相关(我在 Stack Overflow 上读到过可能会存在问题的讨论),因此这方面问题排除。
我已检查了活动、片段、自定义视图和每个连接的适配器,以确保没有在任何地方调用getWindow(我没有调用)。
自定义视图是在运行时从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);
}