title: Placing View Underneath Action Bar
body: <p>I have a custom camera activity in my Android app.  For android devices using KitKat, I needed to account for the visible navigation bar at the bottom of the screen.  To do this, I use the following line to ensure my views are below the navigation bar:</p>
  
  <pre><code>getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN );
  </code></pre>
  
  <p>However, when I do this, one of my views becomes hidden behind the action bar.  I'm trying to account for the height of the action bar by adding a top margin to this view, but it doesn't appear to be correct.</p>
  
  <p>What am I doing wrong?</p>
  
  <p>This is what I would like the view to look like (works on pre-KitKat devices):</p>
  
  <p><img src="https://i.stack.imgur.com/Liqfn.png" alt="enter image description here"></p>
  
  <p>And this is what it currently looks like on Kit Kat devices (you can see that the top of my view is cut off):
  <img src="https://i.stack.imgur.com/h8JPG.png" alt="enter image description here"></p>
  
  <p>Here is my layout:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="fill_parent"
      android:layout_height="fill_parent"
      android:gravity="left"
      android:orientation="vertical" &gt;
  
      &lt;HorizontalScrollView
          android:id="@+id/gallery_scroll_view"
          android:layout_width="fill_parent"
          android:layout_height="wrap_content"
          android:layout_alignParentLeft="true"
          android:layout_alignParentTop="true"
          android:scaleType="fitXY" &gt;
  
          &lt;com.example.helperClass.PictureHorizontalLayout
              android:id="@+id/mygallery"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:orientation="horizontal"
              android:scaleType="fitXY" &gt;
          &lt;/com.example.helperClass.PictureHorizontalLayout&gt;
      &lt;/HorizontalScrollView&gt;
  
      &lt;FrameLayout
          android:id="@+id/camerapreview"
          android:layout_width="fill_parent"
          android:layout_height="fill_parent"
          android:background="@color/black" /&gt;   
  
      &lt;LinearLayout
          android:id="@+id/button_holder_customized_cam"
          android:layout_width="match_parent"
          android:layout_height="55dp"
          android:layout_alignParentBottom="true"
          android:background="#838B8B"
          android:gravity="bottom"
          android:orientation="horizontal"
          android:weightSum="0.9"
          &gt;
  
          &lt;ImageButton
              android:id="@+id/gallery_customized_camera"
              android:layout_width="wrap_content"
              android:layout_height="match_parent"
              android:layout_marginRight="1dp"
              android:layout_weight="0.3"
              android:adjustViewBounds="true"
              android:background="@null"
              android:contentDescription="@string/add"
              android:maxWidth="75dp"
              android:scaleType="center"
              android:src="@drawable/ic_action_picture" &gt;
  
              &lt;!-- android:background="@drawable/custom_button_blue" --&gt;
  
          &lt;/ImageButton&gt;
  
          &lt;ImageButton
              android:id="@+id/shutter_customized_camera"
              android:layout_width="wrap_content"
              android:layout_height="match_parent"
              android:layout_marginRight="1dp"
              android:layout_weight="0.3"
              android:adjustViewBounds="true"
              android:background="@drawable/custom_button_blue"
              android:contentDescription="@string/add"
              android:maxWidth="75dp"
              android:scaleType="center"
              android:src="@drawable/ic_action_camera" &gt;
          &lt;/ImageButton&gt;
  
          &lt;ImageButton
              android:id="@+id/video_customized_camera"
              android:layout_width="wrap_content"
              android:layout_height="match_parent"
              android:layout_weight="0.3"
              android:adjustViewBounds="true"
              android:background="@null"
              android:contentDescription="@string/add"
              android:maxWidth="75dp"
              android:scaleType="center"
              android:src="@drawable/ic_action_video" &gt;
  
              &lt;!-- android:background="@drawable/custom_button_blue" --&gt;
  
          &lt;/ImageButton&gt;
      &lt;/LinearLayout&gt;
  
      &lt;TextView
          android:id="@+id/camera_timer"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_above="@id/button_holder_customized_cam"
          android:layout_alignParentRight="true"
          android:padding="15dp"
          android:text="@string/no_time"
          android:textColor="@color/red"
          android:textSize="20sp"
          android:visibility="invisible" &gt;
      &lt;/TextView&gt;
  
  &lt;/RelativeLayout&gt;
  </code></pre>
  
  <p>And here is how I set margins for the HorizontalScrollView:</p>
  
  <pre><code>  myHorizontalLayout = (PictureHorizontalLayout) findViewById(R.id.mygallery);
    // apply margin to horizontal scroll view to take into account height of status bar
      TypedValue tv = new TypedValue();
      int actionBarHeight  = 0;
      if (getTheme().resolveAttribute(android.R.attr.actionBarSize, tv, true))
      {
          actionBarHeight = TypedValue.complexToDimensionPixelSize(tv.data,getResources().getDisplayMetrics());
          Log.d(TAG, "actionbarHeight before: " + actionBarHeight);
          FrameLayout.LayoutParams params = (FrameLayout.LayoutParams) myHorizontalLayout.getLayoutParams();
          Log.d(TAG, "actionbarHeight after: " + actionBarHeight);
          params.setMargins(0, actionBarHeight, 0, 0);
          Log.d(TAG, "ADJUST MARGINS OF HORIZONTAL LAYOUT");
          myHorizontalLayout.setLayoutParams(params);
      }     
  </code></pre>
  
  <p>NOTE: I also tried adding <code>android:layout_marginTop="?attr/actionBarSize"</code> to the HorizontalScrollView in my layout file, but this didn't work either (the vertical offset was still incorrect)</p>