国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統 > Android > 正文

Android實現微信朋友圈評論EditText效果

2019-10-21 21:35:05
字體:
來源:轉載
供稿:網友

本文主要講解實現微信朋友圈評論EditText效果思路,供大家參考,具體內容如下

效果圖

Android,微信朋友圈,EditText

當我們點擊某一天朋友圈的評論是,列表也會跟隨著滑動,使得鍵盤剛好在我們點擊的那條評論上方

getWindow().getDecorView().getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {  @Override  public void onGlobalLayout() {  // 這里可以監聽到鍵盤顯示與隱藏時界面可視區域的變化  Rect rect = new Rect();  View decorView = getWindow().getDecorView();  decorView.getWindowVisibleDisplayFrame(rect);  int displayHeight = rect.bottom - rect.top;  // 拿到鍵盤的高度,可能會有誤差,需要優化  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];  }

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持VEVB武林網。


注:相關教程知識閱讀請移步到Android開發頻道。
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 芮城县| 平定县| 株洲县| 顺义区| 玉环县| 宁阳县| 德兴市| 东乌珠穆沁旗| 大冶市| 全南县| 务川| 东乡族自治县| 尉氏县| 龙岩市| 吉安县| 临江市| 尼勒克县| 竹北市| 荣昌县| 大冶市| 丹凤县| 松江区| 深州市| 大竹县| 嘉鱼县| 临颍县| 华池县| 顺平县| 杭州市| 沂源县| 荥阳市| 荣成市| 呼伦贝尔市| 于田县| 科技| 宣汉县| 兴仁县| 宣城市| 望奎县| 来安县| 商河县|