关于Edittext点击弹出软键盘,布局上移标题消失问题,微信聊天界面
16lz
2021-01-24
最近遇到了关于软键盘弹出,布局上移动的解决
当edittext获取焦点呢,弹出软键盘,布局上移,标题位置不变,
1,取消activity设置, Activity 设置 android:windowSoftInputMode=""
2.主布局增加Scrollview包裹主布局,并且设置属性
android:fillViewport="true"
<?xml version="1.0" encoding="utf-8"?><ScrollView xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="match_parent" android:fillViewport="true" >
3,关于
当ScrollView里的元素想填满ScrollView时,使用"fill_parent"是不管用的,必需为ScrollView设置:android:fillViewport="true"。
当ScrollView没有fillVeewport=“true”时, 里面的元素(比如LinearLayout)会按照wrap_content来计算(不论它是否设了"fill_parent"),
而如果LinearLayout的元素设置了fill_parent,那么也是不管用的,因为LinearLayout依赖里面的元素,而里面的元素又依赖LinearLayout,
这样自相矛盾.所以里面元素设置了fill_parent,也会当做wrap_content来计算.
< LinearLayout android :layout_width= "fill_parent" android :layout_height= "wrap_content" android :orientation= "vertical" > < LinearLayout android :id= "@+id/logo" android :layout_width= "fill_parent" android :layout_height= "wrap_content" android :layout_marginTop= "20dip" android :layout_weight= "1" android :gravity= "bottom|center_horizontal" android :orientation= "vertical" > < ImageView android :id= "@+id/imageView1" android :layout_width= "wrap_content" android :layout_height= "wrap_content" /> < ImageView android :id= "@+id/serviceimg" android :layout_width= "wrap_content" android :layout_height= "wrap_content" /> LinearLayout > < FrameLayout android :id= "@+id/layout_main" android :layout_width= "fill_parent" android :layout_height= "wrap_content" android :layout_weight= "1" android :gravity= "top|center_horizontal" android :orientation= "vertical" android :visibility= "visible" > FrameLayout > < RadioGroup android :id= "@+id/radioGroup" android :layout_width= "fill_parent" android :layout_height= "wrap_content" android :orientation= "horizontal" > < RadioButton android :id= "@+id/bu1" android :layout_width= "wrap_content" android :background= "#da1111" android :text= "聊天界面" android :layout_height= "wrap_content" /> < RadioButton android :id= "@+id/bu2" android :layout_width= "wrap_content" android :background= "#ffaa12" android :button= "@null" android :text= "聊你妹啊" android :layout_height= "wrap_content" /> RadioGroup > LinearLayout > ScrollView >试试吧,测试没问题
2。附加一个简单检测软键盘的弹出,通过软键盘是否弹出,隐藏底部菜单。
main_cro.addOnLayoutChangeListener(new View.OnLayoutChangeListener() { @Override public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) { //Toast.makeText(v.getContext(),bottom+"|"+oldLeft+"|"+oldTop+"|"+oldBottom,Toast.LENGTH_LONG).show(); if((bottom-oldBottom)<-100){ radioGroup.setVisibility(View.GONE); }if((bottom-oldBottom)>200){ radioGroup.setVisibility(View.VISIBLE); } }});
main_cro是主布局id,根据参数调试。。
更多相关文章
- Android(安卓)程序员学习 iOS ——UIViewController 和 Layout S
- android中的5个布局方式
- Android(安卓)view 的布局学习
- Android自定义ScrollView实现反弹效果
- 构建 Android(安卓)手机 RSS 阅读器
- Android(安卓)8.0 SystemUI下拉状态栏快捷开关
- 【Android(安卓)开发】:UI控件之复选框控件 CheckBox 的使用方法
- 在iPhone 和 Android设备上,HTML5的关于键盘的输入类型
- Android(安卓)DrawerLayout 高仿QQ5.2双向侧滑菜单