键盘将“片段"中的“活动"项移动 [英] Keyboard moves item of the Activity in Fragment
问题描述
在应用程序的 MainActivity 中,我有一个自定义底部导航,它是水平的回收站视图.我可以在所有片段中访问此recyclerview进行导航.问题是,当我专注于片段中的 edittext 时,软输入法将recyclerview向上移动,如何强制屏幕平移片段中布局中的项目.
In my application's MainActivity I have a custom bottom navigation which is a horizontal recyclerview. I have an access to this recyclerview in all of my Fragments for navigation. The thing is when I focus on an edittext inside my fragment, soft input method moves that recyclerview up, how can I force the screen to pan just for the items in my Fragment's layout.
[![这是我的片段,其中有活动的底部导航] [2]] [2]
[![here is my fragment with activity's bottom navigation][2]][2]
[![在此处输入图片描述] [3]] [3]
[![enter image description here][3]][3]
我尝试在清单中将android:windowSoftInputMode="adjustPan"
和android:windowSoftInputMode="adjustNothing"
放到我的活动中.
I tried to put android:windowSoftInputMode="adjustPan"
and then android:windowSoftInputMode="adjustNothing"
to my activity in my Manifest.
然后我尝试以编程方式在活动"中执行这些操作.
then I tried to do those programatically inside my Activity.
然后,这次我尝试在片段内执行相同的操作 ,但没有任何帮助.从字面上看,没有办法使键盘忽略该活动.
then I tried to do the same inside my Fragment this time, nothing helped. Literally no way to make the keyboard ignore the activity.
主要活动布局:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#d9d5ce"
android:orientation="vertical"
android:focusableInTouchMode="true"
>
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="@drawable/toolbar_background"
android:theme="@style/ToolBarStyle"
app:layout_collapseMode="pin"
app:layout_scrollFlags="scroll|enterAlways"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
app:titleTextAppearance="@style/TextAppearance.AppCompat.Subhead" />
<FrameLayout
android:id="@+id/frame_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@+id/recycler_view"
android:layout_gravity="center"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
</FrameLayout>
<android.support.v7.widget.RecyclerView
android:id="@+id/recycler_view"
android:layout_width="match_parent"
android:layout_height="65dp"
android:layout_alignParentBottom="true"
android:background="@color/accent"
android:fadingEdge="vertical|horizontal"
android:fadingEdgeLength="60dp"
android:fillViewport="false"
android:requiresFadingEdge="horizontal|vertical"
app:layoutManager="android.support.v7.widget.LinearLayoutManager">
</android.support.v7.widget.RecyclerView>
</RelativeLayout>
我已经尝试过android:windowSoftInputMode="adjustPan"
之类的可能解决方案,问题是当片段中的edittext获得焦点时,活动中的Recyclerview向上移动而我失去平移
I already tried possible solutions like android:windowSoftInputMode="adjustPan"
the problem is when the edittext inside fragment gain focus, Recyclerview in my activity moves up and I lost pan
仅供参考:我片段的根目录为ScrollView
FYI: my fragment's root layout is ScrollView
推荐答案
我通过观察键盘和设置导航栏的可见性来解决此问题.这是完整的解决方案:
I solved this by observing the keyboard and set visibility of the nav bar. here is the full solution:
https://medium.com/@egek92/beaware-of-android-bug-5497-for-your-own-sake-19cf76abb7e5
这篇关于键盘将“片段"中的“活动"项移动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!