【发布时间】:2016-11-29 15:11:23
【问题描述】:
我有以下布局
<?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:animateLayoutChanges="true">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</android.support.design.widget.AppBarLayout>
<ScrollView
android:id="@+id/scroll_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
<!-- Content -->
</ScrollView>
<include layout="@layout/fixed_layout_when_keyboard_not_visible" />
</RelativeLayout>
在 AndroidManifest 中,我将 android:windowSoftInputMode 设置为 adjustResize,它不会在键盘可见时“挤压”内容,并且始终保持工具栏固定,即使在我滚动时也是如此。
但是,我在底部有另一个视图,在 ScrollView 之外,我也想修复它,但同时在键盘弹出时不阻止任何内容 - 现在它与键盘一起移动,如下所示属性layout_gravity="bottom"。
我可以在键盘显示/隐藏时切换该布局的可见性,但这似乎不是最优雅的解决方案。你有什么建议?非常感谢任何帮助:)
【问题讨论】:
-
我相信聆听软键盘并隐藏/显示视图是实现您所需的最佳方式。 android 的默认行为是 ether 显示或隐藏整个内容。
标签: android android-layout android-softkeyboard window-soft-input-mode