我正在尝试在聊天应用中实现以下视图.基本上有两种状态,一种是软触键盘显示,另一种是没有.
这是键盘出现时发生的情况.
这就是我想要实现的目标.
注意
我目前正在使用“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);
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。