繁体   English   中英

键盘弹起时,Android Fragment视图不滚动

[英]Android Fragment view does not scroll when keyboard is up

我正在加载这样的片段

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

活动已设置此属性

android:windowSoftInputMode="adjustResize"

在我看来,底部有一个按钮,我想一直保持在键盘上方。 这是我的片段布局文件的样子

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

我在此视图中有一个EiditText,当我请求聚焦时,软键盘出现,但视图不滚动。

谁能告诉我为什么键盘打开时视图没有调整大小?

我找到了两个对我有用的解决方案

将其放在片段的onCreate中:

getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE|WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);

要么

使用ScrollView作为Activity中FrameLayout的父级,如下所示:

<ScrollView>
    <FrameLayout/>
</ScrollView>

尝试此操作,更改Parent RelativeLayout`

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM