title: View is in the last position of parent, but still being blocked
body: <h3>What I want to do</h3>
  
  <p>In a <code>BottomSheetDialogFragment</code>, I want to inflate a view that always stick at the bottom of the screen, no matter what <a href="https://developer.android.com/reference/android/support/design/widget/BottomSheetBehavior.html" rel="nofollow noreferrer">state (collapsed / expanded)</a> the <code>BottomSheetBehavior</code> is in.</p>
  
  <h3>What I have done</h3>
  
  <p>In a subclass of <code>BottomSheetDialogFragment</code>, I inflate a view from XML and add it as a child of <code>CoordinatorLayout</code> (which is <code>BottomSheetDialogFragment</code>'s parent's parent):</p>
  
  <pre><code>@Override
  public void onActivityCreated(Bundle savedInstanceState) {
      super.onActivityCreated(savedInstanceState);
      setupBottomBar(getView());
  }
  
  private void setupBottomBar (View rootView) {
      CoordinatorLayout parentView = (CoordinatorLayout) ((FrameLayout)rootView.getParent()).getParent();
      parentView.addView(LayoutInflater.from(getContext()).inflate(R.layout.item_selection_bar, parentView, false), -1);
  }
  </code></pre>
  
  <p>The code runs without error.<br>
  And when I use Layout Inspector to look at the View hierarchy, the view structure is also correct:</p>
  
  <p><a href="https://i.stack.imgur.com/WRlFP.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/WRlFP.png" alt="Layout Inspector Screenshot"></a></p>
  
  <p>You can also download the layout inspector result <a href="http://s000.tinyupload.com/index.php?file_id=34813213334752691638" rel="nofollow noreferrer">here</a>, and open it using your own Android Studio.</p>
  
  <h3>The problem</h3>
  
  <p>However, even though it is inserted as the last child of the <code>CoordinatorLayout</code>, it is still being blocked by the <code>BottomSheetDialogFragment</code>.<br>
  When I slowly scroll the <code>BottomSheetDialogFragemnt</code> downwards (from collapsed state to hidden state), I can finally see the view that I want to inflate behind the fragment.</p>
  
  <p><a href="https://i.stack.imgur.com/slmOg.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/slmOg.png" alt="View blocked"></a></p>
  
  <p>Why is this happening?</p>
  
  <h2>The answer</h2>
  
  <p>As @GoodDev pointed out correctly, it is because the root view (design_bottom_sheet) has been set a Z translation by <code>BottomSheetDialog</code>.<br>
  This provides an important information that - <strong>not only sequence in a View hierarchy will determine its visibility, but also its Z translation.</strong> </p>
  
  <p>The best way is to get the Z value of <code>design_bottom_sheet</code> and set it to the bottom bar layout.</p>
  
  <pre><code>private void setupBottomBar (View rootView) {
      CoordinatorLayout parentView = (CoordinatorLayout) (rootView.getParent().getParent());
      View barView = LayoutInflater.from(getContext()).inflate(R.layout.item_selection_bar, parentView, false);
      ViewCompat.setTranslationZ(barView, ViewCompat.getZ((View)rootView.getParent()));
      parentView.addView(barView, -1);
  }
  </code></pre>