介绍
小编给大家分享一下安卓如何实现微信朋友圈评论EditText效果,希望大家阅读完这篇文章之后都有所收获、下面让我们一起去探讨吧!
具体内容如下
效果图
当我们点击某一天朋友圈的评论是,列表也会跟随着滑动,使得键盘刚好在我们点击的那条评论上方
getWindow () .getDecorView () .getViewTreeObserver () .addOnGlobalLayoutListener (new ViewTreeObserver.OnGlobalLayoutListener (), { @Override才能 public 才能;void  onGlobalLayout (), {//才能,这里可以监听到键盘显示与隐藏时界面可视区域的变化 Rect 才能;Rect =, new 矩形(); View 才能;decorView =, getWindow () .getDecorView (); decorView.getWindowVisibleDisplayFrame才能(矩形); int 才能;displayHeight =, rect.bottom 作用;rect.top;//,才能拿到键盘的高度,可能会有误差,需要优化 keyboardHeight 才能=,decorView.getHeight(),安康;displayHeight; if 才能;(displayHeight *, 1.0,/, decorView.getHeight(),祝辞,0.8),{ ,,dialog.dismiss (); ,,} ,,} 以前,});>考虑到评论的EditText是可以隐藏的,所以把它写到对话框中,初始化对话框的代码就不贴出来了
点击弹出对话框
private void showInputComment (View commentView, final int 位置),{//,,,拿到评论按钮在屏幕中的坐标 ,,final int  rvInputY =, getY (commentView);//,,,拿到评论按钮高度 ,,final int  rvInputHeight =, commentView.getHeight (); ,,dialog.show (); ,,handler.postDelayed (new Runnable (), { ,,@Override ,,,public void 运行(),{ ,,,,int dialogY =, getY (dialog.findViewById (R.id.dialog_layout_comment)); ,,,,//,滑动列表 ,,,,rv.smoothScrollBy (0,, rvInputY 作用;keyboardHeight +, dialogY +, rvInputHeight); ,,,} ,,,},300); ,,} ,/* * ,,*,拿到视图在屏幕中的坐标 ,,*,@param commentView ,,* @return ,,*/private 才能;int  getY (View commentView), { ,,int [], outLocation =, new int [2]; ,,commentView.getLocationOnScreen (outLocation); ,,return outLocation [1]; 以前,,}>看完了这篇文章,相信你对“Android如何实现微信朋友圈评论EditText效果”有了一定的了解,如果想了解更多相关知识,欢迎关注行业资讯频道,感谢各位的阅读!
Android如何实现微信朋友圈评论EditText效果