title: How to place a layout completely on top of keyboard in bottom sheet dialog fragment
body: <p>I have a <code>bottom sheet dialog fragment</code> in an <code>Activity</code>. When the <code>softkeyboard</code> is shown I need to push the complete <code>dialog fragment layout</code> to the top of <code>keyboard</code>.</p>
  
  <p>I have tried various ways like using <code>GRAVITY.TOP</code> , <code>bottomMargin</code> for the <code>dialog</code> increasing the height etc.</p>
  
  <p>None of the above ways are working. I want to make the top of <code>bottom sheet dialog fragment</code> align with the <code>parent</code> i.e top of phone.</p>
  
  <p>Since I am using <code>Framelayout</code> to add <code>Bottom Sheet Dialog fragment</code> in <code>activity</code> I am unable to set <code>alignParentTopAttribute</code> . Please let me know if there are any ways of doing this or suggestions to achieve this.</p>
  
  <p>Please find below code that I have tried till now:</p>
  
  <pre><code>view?.viewTreeObserver?.addOnGlobalLayoutListener {
      var r = Rect()
      view?.getWindowVisibleDisplayFrame(r)
      var screenHeight = view?.rootView?.height
      var initialHeight = rootLayout.height
      var keyPadHeight = screenHeight?.minus(r.bottom)
  
      var layoutParams: Frame.LayoutParams = FrameLayout.LayoutParams(
          FrameLayout.LayoutParams.WRAP_CONTENT,
          FrameLayout.LayoutParams.WRAP_CONTENT
      )
      if (keyPadHeight!! &gt; screenHeight?.times(0.15)!!) {// 0.15 ratio is perhaps enough to determine keypad height.
          // keyboard is opened
          if (!isKeyboardShowing) {
              isKeyboardShowing = true
          }
          var window: Window? = dialog?.window
          var windowManagerLayoutParams: WindowManager.LayoutParams? = window?.attributes
         //Tried this
          windowManagerLayoutParams.gravity = GRAVITY.TOP
          window.attributes = windowManagerLayoutParams
  
         //Tried this
         layoutParams.gravity = Gravity.TOP
         rootLayout.layoutParams = layoutParams
      } else {
          // keyboard is closed
          if (isKeyboardShowing) {
              isKeyboardShowing = false
          }
      }
  }
  </code></pre>
  
  <p>I have also tried <code>adjustResize</code> and <code>stateVisible</code> in <code>manifest</code>. <code>adjustResize</code> will not push complete <code>layout</code> to the top of <code>soft keyboard</code>, there will be a <code>scroll</code> behind the <code>soft keyboard</code>, user will have to <code>scroll</code> to see the complete <code>layout</code>.
  But I do not want to have the scroll, user should see the complete layout on top of the <code>soft keyboard</code> as soon as it is visible.</p>