[英]Android Fragment view does not scroll when keyboard is up
I am loading a fragment like this 我正在加载这样的片段
String tag = fragment.getClass().getSimpleName();
FragmentManager fragmentManager = getFragmentManager();
FragmentTransaction transaction = fragmentManager.beginTransaction();
transaction.replace(android.R.id.content, fragment,tag);
transaction.addToBackStack(tag);
transaction.commit();
The activity has this property set 活动已设置此属性
android:windowSoftInputMode="adjustResize"
In my view I have a button at the bottom that I want to keep on top of the keyboard. 在我看来,底部有一个按钮,我想一直保持在键盘上方。 This is what my fragment layout file looks like
这是我的片段布局文件的样子
<RelativeLayout xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:fillViewport="true"
android:isScrollContainer="true">
<LinearLayout..../>
</ScrollView>
<Button
android:id="@+id/activate_button"
style="@android:style/Widget.DeviceDefault.Light.Button.Borderless.Small"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true" />
</RelativeLayout>
I have an EiditText in this view and when I request focus the soft keyboard appears but view doesn't scroll. 我在此视图中有一个EiditText,当我请求聚焦时,软键盘出现,但视图不滚动。
Can anyone tell me why view is not resizing when keyboard is up? 谁能告诉我为什么键盘打开时视图没有调整大小?
I found two solutions that worked for me 我找到了两个对我有用的解决方案
Put this in the onCreate of your fragment: 将其放在片段的onCreate中:
getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE|WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
Or 要么
Use a ScrollView as parent of your FrameLayout in the Activity, like this: 使用ScrollView作为Activity中FrameLayout的父级,如下所示:
<ScrollView>
<FrameLayout/>
</ScrollView>
Try this, Change Parent RelativeLayout ` 尝试此操作,更改Parent RelativeLayout`
android:layout_height="wrap_content" into android:layout_height="match_parent" android:layout_height =“ wrap_content”转换为android:layout_height =“ match_parent”
<RelativeLayout xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<Button
android:id="@+id/activate_button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginBottom="10dp"/>
</RelativeLayout>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.