国产探花免费观看_亚洲丰满少妇自慰呻吟_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開發頻道。
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 陈巴尔虎旗| 鄂托克旗| 平果县| 金堂县| 鄂伦春自治旗| 同德县| 邵武市| 肥乡县| 玉门市| 扎鲁特旗| 怀集县| 罗定市| 象州县| 瑞丽市| 攀枝花市| 宜都市| 逊克县| 宜春市| 旬阳县| 夏津县| 固阳县| 望城县| 子长县| 澳门| 大关县| 三明市| 大埔县| 将乐县| 临城县| 尖扎县| 洪江市| 政和县| 会泽县| 黄梅县| 新巴尔虎左旗| 伊通| 筠连县| 皋兰县| 新丰县| 枝江市| 饶阳县|