最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Android實(shí)現(xiàn)微信朋友圈評論EditText效果

 更新時(shí)間:2022年08月02日 11:27:49   作者:candy_rjr  
這篇文章主要為大家詳細(xì)介紹了Android實(shí)現(xiàn)微信朋友圈評論EditText效果,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文主要講解實(shí)現(xiàn)微信朋友圈評論EditText效果思路,供大家參考,具體內(nèi)容如下

效果圖

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

getWindow().getDecorView().getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
  @Override
  public void onGlobalLayout() {
  // 這里可以監(jiān)聽到鍵盤顯示與隱藏時(shí)界面可視區(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的代碼就不貼出來了

點(diǎn)擊彈出Dialog

private void showInputComment(View commentView, final int position) {
   // 拿到評論按鈕在屏幕中的坐標(biāo)
   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));
     // 滑動(dòng)列表
     rv.smoothScrollBy(0, rvInputY - keyboardHeight + dialogY + rvInputHeight);
    }
   }, 300);
  }

  /**
   * 拿到View在屏幕中的坐標(biāo)
   * @param commentView
   * @return
   */
  private int getY(View commentView) {
   int[] outLocation = new int[2];
   commentView.getLocationOnScreen(outLocation);
   return outLocation[1];
  }

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評論

屏东市| 汤阴县| 涟源市| 通许县| 久治县| 元氏县| 尼勒克县| 沙湾县| 锦州市| 波密县| 天津市| 嘉禾县| 新余市| 金乡县| 甘孜县| 武穴市| 阿鲁科尔沁旗| 阳新县| 上栗县| 衡水市| 紫阳县| 定边县| 含山县| 柏乡县| 泸定县| 康保县| 福海县| 东丰县| 蓝田县| 罗源县| 辽中县| 从化市| 大方县| 舞阳县| 通榆县| 全州县| 彰武县| 天峨县| 甘南县| 奉化市| 安化县|