隐藏软键盘的时候,页面或者布局往上跳动的解决办法

来源:互联网 发布:数据聚合是什么意思 编辑:程序博客网 时间:2024/06/05 16:38

最近在做项目的时候,遇到,点击输入输入框文字后,回车的时候,软键盘隐藏时,页面和布局往上跳动一下,恢复正常,搞得体验非常不好,

 其实这个问题,很好解决:

 以下是我的解决办法:

 <EditText             android:id="@+id/et_contact"             android:layout_width="match_parent"             android:layout_height="@dimen/dp_40"             android:layout_alignParentRight="true"             android:layout_centerVertical="true"             android:layout_toRightOf="@id/contact"             android:background="@null"             android:gravity="center_vertical"             android:hint="请输入你的名字"             android:imeOptions="actionDone"             android:maxLength="20"             android:paddingRight="@dimen/dp_15"             android:singleLine="true"             android:textColor="@color/content_color"             android:textSize="@dimen/size_14"/>
Activty中
   et_phone.setOnKeyListener(this);@Override    public boolean onKey(View v, int keyCode, KeyEvent event) {        if (KeyEvent.KEYCODE_ENTER == keyCode && KeyEvent.ACTION_DOWN == event.getAction()) {            //处理事件            hideSoftKeyboard();            return true;        }        return false;    }



这样他会很平和的隐藏软键盘,不会造成页面跳动!!! 如果能解决你的问题,不要忘记了点赞!!!

关注本人博客地址链接:https://github.com/wolfking0608

阅读全文
0 0
原创粉丝点击