Android 软键盘将指定的布局顶上去

来源:互联网 发布:mysql不能删除数据 编辑:程序博客网 时间:2024/06/05 18:25

开场白:经常在耳边听到测试或者产品说:“为什么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);滚动到底部

原创粉丝点击