欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

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

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

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

效果圖

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

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;
  // 拿到鍵盤的高度,可能會(huì)有誤差,需要優(yōu)化
  keyboardHeight = decorView.getHeight() - displayHeight;
  if (displayHeight * 1.0 / decorView.getHeight() > 0.8) {
   dialog.dismiss();
  }
  }
 });

考慮到評(píng)論的EditText是可以隱藏的,所以把它寫到Dialog中,初始化Dialog的代碼就不貼出來(lái)了

點(diǎn)擊彈出Dialog

private void showInputComment(View commentView, final int position) {
   // 拿到評(píng)論按鈕在屏幕中的坐標(biāo)
   final int rvInputY = getY(commentView);
   // 拿到評(píng)論按鈕高度
   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];
  }

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

相關(guān)文章

最新評(píng)論