Is there a better way to get exact screen position of objects in windowed mode?
<p>Trying to move some <code>ImageView</code> objects around in relation to other <code>ImageView</code> objects but the coordinates I am getting from <code>getLocationOnScreen(int[])</code> do not match what is on the screen.  Also one object is being placed above the "parent" and the other is being placed below the "parent".  adjusting the height of app_bar_main affects the positioning as well.  I'm having a hard time with this.  All I want is one object to be placed in the middle of the other...  Please help.</p>

<p>FYI x coord is working fine in portrait and LANDSCAPE oddly enough.</p>

<p>Both markers use the same code to center themselves.</p>

<p><a href="https://i.stack.imgur.com/caMYk.jpg" rel="nofollow noreferrer">enter image description here</a></p>

<pre><code>//Centers the position marker on the slider graphic
public void centerSlider(){
    ImageView sliderPosition = (ImageView) rootview.findViewById(R.id.iv_slider_position);
    int posXY[] = new int[2];
    rootview.findViewById(R.id.iv_slider).getLocationOnScreen(posXY);
    int centerX = posXY[0] + ((rootview.findViewById(R.id.iv_slider)).getWidth() / 2);
    int centerY = posXY[1] - ((rootview.findViewById(R.id.iv_slider)).getHeight() / 2);
    sliderPosition.setX(centerX - (rootview.findViewById(R.id.iv_slider_position).getWidth() / 2));
    sliderPosition.setY(centerY - (rootview.findViewById(R.id.iv_slider_position).getHeight() / 2));
}
</code></pre>

<p>This is the Layout
    
    </p>

<pre><code>&lt;ImageView
    android:layout_width="200dp"
    android:layout_height="200dp"
    app:srcCompat="@drawable/joystick3"
    android:id="@+id/iv_joystick"
    android:layout_alignParentTop="true"
    android:layout_alignParentRight="true"/&gt;

&lt;ImageView
    ads:srcCompat="@drawable/ball"
    android:id="@+id/iv_joystick_position"
    android:layout_height="50dp"
    android:layout_width="50dp"
    android:layout_alignBottom="@+id/iv_joystick"
    android:layout_alignLeft="@+id/iv_joystick"
    android:layout_marginBottom="5dp"
    android:layout_centerInParent="false" /&gt;

&lt;GridLayout
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true"
    android:layout_marginLeft="10dp"
    android:layout_marginTop="10dp"
    android:layout_width="wrap_content"&gt;

    &lt;TextView
        android:text="@string/live_damp_start"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/tv_damp_start"
        android:textColor="@color/live_control_text_ui"
        android:layout_row="0"
        android:layout_column="0"
        android:textStyle="normal|bold"
        android:textSize="14sp"
        android:layout_columnSpan="2" /&gt;

    &lt;SeekBar
        android:layout_width="150dp"
        android:layout_height="wrap_content"
        android:id="@+id/sb_damp_start"
        android:layout_row="1"
        android:layout_column="0"
        android:layout_columnSpan="2" /&gt;

    &lt;TextView
        android:text="@string/live_damp_end"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/tv_damp_end"
        android:textColor="@color/live_control_text_ui"
        android:layout_row="2"
        android:layout_column="0"
        android:textSize="14sp"
        android:textStyle="normal|bold"
        android:layout_columnSpan="2" /&gt;

    &lt;SeekBar
        android:layout_width="150dp"
        android:layout_height="wrap_content"
        android:id="@+id/sb_damp_end"
        android:layout_row="3"
        android:layout_column="0"
        android:layout_columnSpan="2" /&gt;

    &lt;TextView
        android:text="@string/invert"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/textView5"
        android:textColor="@color/live_control_text_ui"
        android:textStyle="normal|bold"
        android:textSize="15sp"
        android:layout_column="0"
        android:layout_row="4" /&gt;

    &lt;CheckBox
        android:text="@string/pan"
        android:textColor="@color/live_control_text_ui"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/checkBox"
        android:layout_row="5"
        android:layout_column="0" /&gt;

    &lt;CheckBox
        android:text="@string/tilt"
        android:textColor="@color/live_control_text_ui"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/checkBox2"
        android:layout_row="6"
        android:layout_column="0" /&gt;

    &lt;CheckBox
        android:text="@string/slide"
        android:textColor="@color/live_control_text_ui"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/checkBox3"
        android:layout_row="7"
        android:layout_column="0" /&gt;

    &lt;TextView
        android:text="@string/return_center"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/textView6"
        android:textColor="@color/live_control_text_ui"
        android:textStyle="normal|bold"
        android:textSize="15sp"
        android:layout_column="1"
        android:layout_row="4"
        android:layout_marginLeft="10dp" /&gt;

    &lt;CheckBox
        android:text="@string/pan"
        android:textColor="@color/live_control_text_ui"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/checkBox4"
        android:layout_row="5"
        android:layout_column="1"
        android:layout_marginLeft="10dp" /&gt;

    &lt;CheckBox
        android:text="@string/tilt"
        android:textColor="@color/live_control_text_ui"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/checkBox5"
        android:layout_row="6"
        android:layout_column="1"
        android:layout_marginLeft="10dp" /&gt;

    &lt;CheckBox
        android:text="@string/slide"
        android:textColor="@color/live_control_text_ui"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/checkBox6"
        android:layout_row="7"
        android:layout_column="1"
        android:layout_marginLeft="10dp" /&gt;

&lt;/GridLayout&gt;

&lt;com.google.android.gms.ads.AdView
    android:id="@+id/ad_view"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true"
    android:layout_alignParentRight="true"
    android:layout_alignParentEnd="true"
    ads:adSize="SMART_BANNER"
    ads:adUnitId="@string/banner_ad_unit_id" /&gt;

&lt;ImageView
    android:layout_width="500dp"
    android:layout_height="60dp"
    app:srcCompat="@drawable/slider3"
    android:id="@+id/iv_slider"
    android:layout_above="@+id/ad_view"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true"
    android:layout_marginBottom="70dp" /&gt;

&lt;ImageView
    ads:srcCompat="@drawable/ball"
    android:id="@+id/iv_slider_position"
    android:layout_height="50dp"
    android:layout_width="50dp"
    android:layout_alignBottom="@+id/iv_slider"
    android:layout_alignLeft="@+id/iv_slider"
    android:layout_marginBottom="5dp"
    android:layout_centerInParent="false" /&gt;

&lt;/RelativeLayout&gt;
</code></pre>