美文网首页
【Android】仿QQ空间,快手点击item移动到软键盘上面

【Android】仿QQ空间,快手点击item移动到软键盘上面

作者: 下雨天的小白鞋 | 来源:发表于2020-04-16 17:11 被阅读0次

解决软键盘遮挡问题

scrollview移动距离=点击item的坐标-弹出软键盘过后的edittext的坐标+点击item的高度

 // listview的y坐标 - 输入框的y坐标。
                        final int[] coord = new int[2];
                        int y2 = 0;
                        if (view != null) {
                            view.getLocationOnScreen(coord);
                            y2 = coord[1];
                            final int[] coord2 = new int[2];
                            mInput.getLocationOnScreen(coord2);
                            int y = coord2[1];
                            int commentViewHeight = view.getHeight();
                            distance = y2 - y + commentViewHeight;
           
                        }

移动scrollview的距离(上移)

int margin = -distance;
scrollView.setTranslationY(margin);

scrollview回到原始距离

scrollView.setTranslationY(0);

相关文章

网友评论

      本文标题:【Android】仿QQ空间,快手点击item移动到软键盘上面

      本文链接:https://www.haomeiwen.com/subject/ierdvhtx.html