Android實現(xiàn)微信朋友圈評論EditText效果
本文主要講解實現(xiàn)微信朋友圈評論EditText效果思路,供大家參考,具體內(nèi)容如下
效果圖
當我們點擊某一天朋友圈的評論是,列表也會跟隨著滑動,使得鍵盤剛好在我們點擊的那條評論上方
getWindow().getDecorView().getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { @Override public void onGlobalLayout() { // 這里可以監(jiān)聽到鍵盤顯示與隱藏時界面可視區(qū)域的變化 Rect rect = new Rect(); View decorView = getWindow().getDecorView(); decorView.getWindowVisibleDisplayFrame(rect); int displayHeight = rect.bottom - rect.top; // 拿到鍵盤的高度,可能會有誤差,需要優(yōu)化 keyboardHeight = decorView.getHeight() - displayHeight; if (displayHeight * 1.0 / decorView.getHeight() > 0.8) { dialog.dismiss(); } } });
考慮到評論的EditText是可以隱藏的,所以把它寫到Dialog中,初始化Dialog的代碼就不貼出來了
點擊彈出Dialog
private void showInputComment(View commentView, final int position) { // 拿到評論按鈕在屏幕中的坐標 final int rvInputY = getY(commentView); // 拿到評論按鈕高度 final int rvInputHeight = commentView.getHeight(); dialog.show(); handler.postDelayed(new Runnable() { @Override public void run() { int dialogY = getY(dialog.findViewById(R.id.dialog_layout_comment)); // 滑動列表 rv.smoothScrollBy(0, rvInputY - keyboardHeight + dialogY + rvInputHeight); } }, 300); } /** * 拿到View在屏幕中的坐標 * @param commentView * @return */ private int getY(View commentView) { int[] outLocation = new int[2]; commentView.getLocationOnScreen(outLocation); return outLocation[1]; }
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習有所幫助,也希望大家多多支持腳本之家。
- Android 登錄頁面的實現(xiàn)代碼(密碼顯示隱藏、EditText 圖標切換、限制輸入長度)
- Android EditText隨輸入法一起移動并懸浮在輸入法之上的示例代碼
- Android EditText每4位自動添加空格效果
- Android EditText追加空格、限制字符等方法示例
- Android EditText長按菜單中分享功能的隱藏方法
- Android中多個EditText輸入效果的解決方式
- Android EditText監(jiān)聽回車鍵并處理兩次回調(diào)問題
- Android實現(xiàn)EditText添加下劃線
- Android自定義密碼輸入EditTextLayout
- Android EditText限制輸入整數(shù)和小數(shù)的位數(shù)的方法示例
- Android使用EditText小技巧匯總
相關(guān)文章
Android開發(fā)中synchronized的三種使用方式詳解
這篇文章主要介紹了Android開發(fā)中synchronized的三種使用方式,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習或者工作具有一定的參考學(xué)習價值,需要的朋友們下面隨著小編來一起學(xué)習吧2023-04-04Android入門之LinearLayout、AbsoluteLayout的用法實例講解
這篇文章主要介紹了Android入門之LinearLayout、AbsoluteLayout的用法,對于Android初學(xué)者有很好的參考借鑒價值,需要的朋友可以參考下2014-08-08Android獲取手機型號/系統(tǒng)版本號/App版本號等信息實例講解
本示例獲得手機型號,系統(tǒng)版本,App版本號等信息,具體實現(xiàn)如下,感興趣的朋友可以參考下哈2013-06-06Android 實現(xiàn)手機接通電話后振動提示的功能
本文主要介紹Android 實現(xiàn)手機接通電話后振動提示的功能,這里整理了詳細的相關(guān)資料,并附有示例代碼,有需要的朋友可以參考下2016-08-08