我有一个布局,其中有两个编辑文本和水平滚动条, fragment 中有一些图标。
水平 ScrollView 使用相对布局约束永久固定在父 View 的底部。
单击编辑时,默认会出现软键盘。 当发生这种情况时,我需要水平 ScrollView float 在软键盘上方,以便每个人都可以使用它。
我已将以下行添加到包含该 fragment 的 Activity 的 AndroidManifest.xml 文件中
android:windowSoftInputMode="adjustResize"
View 仍然没有按预期工作。
我该如何解决这个问题?
当前屏幕:
没有键盘的当前屏幕 [Current Screen w/o keyboard] 1
带键盘的当前屏幕 [Current Screen with keyboard] 2
预期屏幕
没有键盘的预期屏幕 [Expected Screen w/o keyboard] 3
带键盘的预期屏幕 [Exoected Screen with keyboard] 4
这是 fragment 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>
我哪里出错了,我该如何解决?
最佳答案
在每个 onCreateView 的 fragment 调用中尝试这个
getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
关于android - 在 Android 的 Fragment 中,布局未 float 在键盘上方,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48677901/