Android线性布局重量和软键盘问题

我正在尝试在聊天应用中实现以下视图.基本上有两种状态,一种是软触键盘显示,另一种是没有.

所以这是我没有键盘显示的初始状态.

enter image description here

这是键盘出现时发生的情况.

enter image description here

这就是我想要实现的目标.

enter image description here

注意
我目前正在使用“adjust-resize”作为windowSoftInputMode.我知道使用“adjust-pan”会解决这个问题,但是“adjust-pan”有两个问题:

>工具栏也向上移动,为编辑文本和键盘腾出空间.
> editText部分由键盘覆盖.

这里需要布局专家的帮助!
提前致谢.

编辑:

这就是我的XML的样子:

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

    <LinearLayout
        android:id="@+id/view_group_toolbar"
        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="?attr/actionBarSize"
            android:background="@color/colorPrimaryDark"
            android:elevation="4dip" >

            <!-- Toolbar stuff -->

        </android.support.v7.widget.Toolbar>

    </LinearLayout>

    <LinearLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_above="@+id/bottom_bar"
        android:layout_below="@+id/view_group_toolbar"
        android:orientation="vertical">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="0.6">

            <include
                layout="@layout/layout_that_covers_60%_of_the_screen (This is not my actual layout name :/ using it for understandability)"
                android:layout_width="match_parent"
                android:layout_height="match_parent" />
        </LinearLayout>

        <LinearLayout
            android:id="@+id/view_group_recycler_view"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="0.4"
            android:gravity="center_vertical">

            <include
                layout="@layout/layout_that_covers_40%_of_the_screen"
                android:layout_width="match_parent"
                android:layout_height="match_parent" />
        </LinearLayout>

    </LinearLayout>

    <RelativeLayout
        android:id="@+id/bottom_bar"
        android:layout_width="match_parent"
        android:layout_height="60dip"
        android:layout_alignParentBottom="true"
        android:gravity="bottom"
        android:padding="8dip" > 
            <!-- This is where my edit text resides -->

    </RelativeLayout> 

</RelativeLayout>

解决方法

所以这就是我认为你应该做的,
使用

windowSoftInputMode =“adjustResize” – 活动的主窗口始终调整大小,以便为屏幕上的软键盘腾出空间. adjustResize还可以将ToolBar保持在最顶层.

尝试在nestedScrollView中添加两个LinearLayouts.我之所以这样说是因为您的nestedScrollView内容可以向上滚动.

我认为你的布局看起来像这样.

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

<LinearLayout
    android:id="@+id/view_group_toolbar"
    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="?attr/actionBarSize"
        android:background="@color/colorPrimaryDark"
        android:elevation="4dip" >

        <!-- Toolbar stuff -->

    </android.support.v7.widget.Toolbar>

</LinearLayout>


<nestedScrollView 
    android:layout_above="@+id/bottom_bar"
    android:layout_below="@+id/view_group_toolbar">
  <LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="0.6">

        <include
            layout="@layout/layout_that_covers_60%_of_the_screen (This is not my actual layout name :/ using it for understandability)"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />
    </LinearLayout>

    <LinearLayout
        android:id="@+id/view_group_recycler_view"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="0.4"
        android:gravity="center_vertical">

        <include
            layout="@layout/layout_that_covers_40%_of_the_screen"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />
    </LinearLayout>

  </LinearLayout>
</nestedScrollView>
<RelativeLayout
    android:id="@+id/bottom_bar"
    android:layout_width="match_parent"
    android:layout_height="60dip"
    android:layout_alignParentBottom="true"
    android:gravity="bottom"
    android:padding="8dip" > 
        <!-- This is where my edit text resides -->

</RelativeLayout>

如果这对您有用,请告诉我.

编辑1:
如果布局中有RecyclerView,则可能需要设置此属性以实现平滑滚动 –

recyclerView.setnestedScrollingEnabled(false);

相关文章

Android性能优化——之控件的优化 前面讲了图像的优化,接下...
前言 上一篇已经讲了如何实现textView中粗字体效果,里面主要...
最近项目重构,涉及到了数据库和文件下载,发现GreenDao这个...
WebView加载页面的两种方式 一、加载网络页面 加载网络页面,...
给APP全局设置字体主要分为两个方面来介绍 一、给原生界面设...
前言 最近UI大牛出了一版新的效果图,按照IOS的效果做的,页...