Android 软键盘将指定的布局顶上去
16lz
2021-01-23
开场白:经常在耳边听到测试或者产品说:“为什么ios可以实现,Android不可以了?”
需求:模仿微信创建拼手气红包的页面。
解决方案:
首先在需要软键盘顶上去的布局外面嵌套ScrollView
<ScrollView android:id="@+id/scrollview" android:layout_width="match_parent" android:layout_height="wrap_content"> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:fitsSystemWindows="true" android:orientation="vertical"> ....这里是需要软键盘顶上去的布局 LinearLayout> ScrollView>
然后onCreate中`
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE | WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
最后监听EditText的点击事件
editText.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View view, MotionEvent motionEvent) { mHandler.post(...这里设置滚动到底部... scrollview.fullScroll(ScrollView.FOCUS_DOWN)); return false; } });
注:
scrollView.fullScroll(ScrollView.FOCUS_DOWN);滚动到底部
更多相关文章
- Android 弹出键盘往上挤压页面
- [图文]为移植到Android平台上的Cocos2d-x项目添加xml布局文件
- Android Notes|细数「八大布局」那些事儿
- Android 和 iPhone 界面布局示例
- Android学习笔记2之基于XML的布局
- Android常用布局(FrameLayout、LinearLayout、RelativeLayout)详解
- Android app性能优化解决卡慢顿之布局优化