布局未在Android的Fragment中的键盘上方浮动 [英] Layout is not floating above keyboard in Fragment in Android

查看:101
本文介绍了布局未在Android的Fragment中的键盘上方浮动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个布局,其中包含两个编辑文本和一个水平滚动条,在片段中带有一些图标.

I have a layout which has two edit texts and horizontal scroll bar with some icons in a fragment.

水平滚动视图使用相对的布局约束永久固定在父级底部.

The horizontal scroll view is permanently fixed to the bottom of the parent using relative layout constraints.

单击编辑后,默认情况下会显示软键盘. 发生这种情况时,我需要水平滚动视图浮在软键盘上方,以便每个人都可以使用它.

When an edit is clicked, the soft keyboard appears by default. When that happens, I need the horizontal scroll view to float above the soft keyboard so that everyone can use it.

我已将以下行添加到包含片段的活动的AndroidManifest.xml文件中

I have added the following line to the AndroidManifest.xml file to the activity containing the fragment

android:windowSoftInputMode="adjustResize"

该视图仍然无法正常工作.

The view still doesn't work as expected.

我该如何解决?

当前屏幕:

不带键盘的当前屏幕 [不带键盘的当前屏幕] 带键盘的当前屏幕 [带键盘的当前屏幕] 预期的屏幕

不带键盘的预期屏幕 [不带键盘的预期屏幕] 带键盘的预期屏幕 [带键盘的预期屏幕] 这是片段xml 文件.

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <io.github.mthli.knife.KnifeText
        android:id="@+id/edt_content"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/title_notes_add"
        android:background="@android:color/transparent"
        android:hint="Content"
        android:padding="12dp"
        android:textSize="20sp"
        app:historyEnable="true"
        app:historySize="20" />

    <EditText
        android:id="@+id/title_notes_add"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@android:color/transparent"
        android:hint="Title"
        android:minLines="1"
        android:padding="12dp"
        android:textSize="24sp"
        android:textStyle="bold" />

    <HorizontalScrollView
        android:id="@+id/tools"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:background="@android:color/white"
        android:scrollbars="none">

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="horizontal">

            <ImageButton
                android:id="@+id/undo"
                android:layout_width="48dp"
                android:layout_height="48dp"
                android:background="?android:selectableItemBackground"
                android:contentDescription="@null"
                android:scaleType="center"
                android:src="@drawable/ic_undo" />

            <ImageButton
                android:id="@+id/redo"
                android:layout_width="48dp"
                android:layout_height="48dp"
                android:background="?android:selectableItemBackground"
                android:contentDescription="@null"
                android:scaleType="center"
                android:src="@drawable/ic_redo" />

            <ImageButton
                android:id="@+id/bold"
                android:layout_width="48dp"
                android:layout_height="48dp"
                android:background="?android:selectableItemBackground"
                android:contentDescription="@null"
                android:scaleType="center"
                android:src="@drawable/ic_format_bold" />

            <ImageButton
                android:id="@+id/italic"
                android:layout_width="48dp"
                android:layout_height="48dp"
                android:background="?android:selectableItemBackground"
                android:contentDescription="@null"
                android:scaleType="center"
                android:src="@drawable/ic_format_italic" />

            <ImageButton
                android:id="@+id/underline"
                android:layout_width="48dp"
                android:layout_height="48dp"
                android:background="?android:selectableItemBackground"
                android:contentDescription="@null"
                android:scaleType="center"
                android:src="@drawable/ic_format_underlined" />

            <ImageButton
                android:id="@+id/strikethrough"
                android:layout_width="48dp"
                android:layout_height="48dp"
                android:background="?android:selectableItemBackground"
                android:contentDescription="@null"
                android:scaleType="center"
                android:src="@drawable/ic_strikethrough" />

            <ImageButton
                android:id="@+id/bullet"
                android:layout_width="48dp"
                android:layout_height="48dp"
                android:background="?android:selectableItemBackground"
                android:contentDescription="@null"
                android:scaleType="center"
                android:src="@drawable/ic_format_list_bulleted" />

            <ImageButton
                android:id="@+id/quote"
                android:layout_width="48dp"
                android:layout_height="48dp"
                android:background="?android:selectableItemBackground"
                android:contentDescription="@null"
                android:scaleType="center"
                android:src="@drawable/ic_format_quote" />

            <ImageButton
                android:id="@+id/link"
                android:layout_width="48dp"
                android:layout_height="48dp"
                android:background="?android:selectableItemBackground"
                android:contentDescription="@null"
                android:scaleType="center"
                android:src="@drawable/ic_insert_link" />

            <ImageButton
                android:id="@+id/clear"
                android:layout_width="48dp"
                android:layout_height="48dp"
                android:background="?android:selectableItemBackground"
                android:contentDescription="@null"
                android:scaleType="center"
                android:src="@drawable/ic_format_clear" />

        </LinearLayout>    
    </HorizontalScrollView>       
</RelativeLayout>

我哪里出错了,该如何解决?

Where have I gone wrong and how do I fix this?

推荐答案

在每个onCreateView的片段调用中尝试使用此方法

Try this in fragment call on each onCreateView

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

这篇关于布局未在Android的Fragment中的键盘上方浮动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆