Fragment上键盘输入问题

有道理 2016-07-04 04:42:06
大神求教个问题,关于在Fragment上键盘弹出的问题,详细描述如下:

这是我们的app页面,MainActivity上是4个Fragment,咨询Fragment是一个聊天页面,期望是点击输入框弹出键盘底部固定不动输入框跟着顶上去,并且标题栏不会被挤上去,但当点击输入框时出现了以下几种情况:
1、 设置android:windowSoftInputMode="adjustPan|stateHidden"时如图:

整个页面被顶上去了;
2、 设置android:windowSoftInputMode="adjustResize|stateHidden"时如图:

输入框被键盘挡住了;
3、 设置MainActivity的跟节点android:fitsSystemWindows="true"
并且android:windowSoftInputMode="adjustResize|stateHidden"时如下图:

输入框跟底部栏一起被顶上去了,想要大神给分析一下!
以下是我的MainActivity布局:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".ui.activity.MainActivity">

<FrameLayout
android:id="@+id/layout_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@+id/linearlayout" />

<LinearLayout
android:id="@+id/linearlayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:orientation="vertical">

<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="@color/colorMainBottomLine" />

<RadioGroup
android:id="@+id/radioGroup"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/colorMainBottombackground"
android:orientation="horizontal">

<RadioButton
android:id="@+id/rb_home"
style="@style/RadioButtnStytle"
android:checked="true"
android:drawableTop="@drawable/selector_main_home"
android:text="@string/rb_home" />

<RadioButton
android:id="@+id/rb_category"
style="@style/RadioButtnStytle"
android:drawableTop="@drawable/selector_main_category"
android:text="@string/rb_category" />

<RadioButton
android:id="@+id/rb_consult"
style="@style/RadioButtnStytle"
android:drawableTop="@drawable/selector_main_consult"
android:text="@string/rb_consult" />

<RadioButton
android:id="@+id/rb_personal"
style="@style/RadioButtnStytle"
android:drawableTop="@drawable/selector_main_personal"
android:text="@string/rb_personal" />
</RadioGroup>
</LinearLayout>
</RelativeLayout>
...全文
479 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复
我的菜单是个Relativelayout,我把他设置gone ,他竟然能显示一块空白,但是仍然占据那么大位置。。。。。。。。
  • 打赏
  • 举报
回复
引用 5 楼 xiao1591 的回复:
基本上解决了,就是隐藏和显示时效果有点小问题! mRoot = getActivity().getWindow().getDecorView(); mRoot.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { @Override public void onGlobalLayout() { Rect rect = new Rect(); mRoot.getWindowVisibleDisplayFrame(rect); int rootInvisibleHeight = mRoot.getRootView().getHeight()-rect.bottom; if(rootInvisibleHeight>100){ //显示 footerView.setVisibility(View.GONE); }else{ //隐藏 footerView.setVisibility(View.VISIBLE); } } });
小哥 你这个footview是edittext吧 难道是activity中的下面的菜单栏么
anye_bbk 2017-08-30
  • 打赏
  • 举报
回复
楼主,怎么保证状态栏不被顶出屏幕?
futianjie_china 2016-12-21
  • 打赏
  • 举报
回复
引用 5 楼 xiao1591 的回复:
基本上解决了,就是隐藏和显示时效果有点小问题! mRoot = getActivity().getWindow().getDecorView(); mRoot.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { @Override public void onGlobalLayout() { Rect rect = new Rect(); mRoot.getWindowVisibleDisplayFrame(rect); int rootInvisibleHeight = mRoot.getRootView().getHeight()-rect.bottom; if(rootInvisibleHeight>100){ //显示 footerView.setVisibility(View.GONE); }else{ //隐藏 footerView.setVisibility(View.VISIBLE); } } });
这里面的下边栏的闪一下的问题解决了吗
qq_25817009 2016-11-09
  • 打赏
  • 举报
回复
你好 我遇到同样的问题 你是怎么解决的啊
qq_34555745 2016-07-20
  • 打赏
  • 举报
回复
这个在你的activity主目录清单中加上 android:windowSoftInputMode="adjustPan|stateHidden" 就OK了
有道理 2016-07-05
  • 打赏
  • 举报
回复

基本上解决了,就是隐藏和显示时效果有点小问题!
mRoot = getActivity().getWindow().getDecorView();
mRoot.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
Rect rect = new Rect();
mRoot.getWindowVisibleDisplayFrame(rect);
int rootInvisibleHeight = mRoot.getRootView().getHeight()-rect.bottom;
if(rootInvisibleHeight>100){
//显示
footerView.setVisibility(View.GONE);
}else{
//隐藏
footerView.setVisibility(View.VISIBLE);
}
}
});
有道理 2016-07-05
  • 打赏
  • 举报
回复
@tudouzi007能发一下吗
tudouzi007 2016-07-05
  • 打赏
  • 举报
回复
具体我没做过,是我同事做的,好像方法是计算输入法的高度,然后让输入框的那个布局向上移动正好到这个高度,差不多就是这个意思
xing880307 2016-07-04
  • 打赏
  • 举报
回复
楼主搞定记得分享下,二楼的权宜之策貌似能凑合实现,在第三种情况下gone隐藏下面的四个按钮
zhao007z5 2016-07-04
  • 打赏
  • 举报
回复
目前应该是做不到你所期望。建议你监听输入法的显示和隐藏。当显示的时候,隐藏掉底部4个分类。输入框隐藏时显示4分类

80,351

社区成员

发帖
与我相关
我的任务
社区描述
移动平台 Android
androidandroid-studioandroidx 技术论坛(原bbs)
社区管理员
  • Android
  • yechaoa
  • 失落夏天
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧