【Android】仿QQ空间,快手点击item移动到软键盘上面
2020-04-16 本文已影响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);