Android: Displaying player icon on map based on coords
<p>I have an image of map (fixed size) to be displayed as background and I want to display a player icon over it. I am getting player's current coords as android.graphic.Point.</p>

<p>I tried RelativeLayout with setting up margins, which kinda worked, but when the display is rotated, the icon is obviously moved elsewhere. Also I think this absolute positioning can't work on different screen size...</p>

<p>Any suggestions how to do this as intended?</p>

<p>This is my XML</p>

<pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:id="@+id/mapLayout"
    tools:context="cz.alois_seckar.vseadventrura.MapActivity"&gt;

    &lt;ImageView
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:id="@+id/playerIcon"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:src="@drawable/player" /&gt;

    &lt;ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/mapImage"
        android:src="@drawable/spacemap"
        android:layout_alignParentTop="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true" /&gt;

    &lt;Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/back_button"
        android:id="@+id/mapBackButton"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true"
        android:onClick="goBack"/&gt;

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

<p>And this is how I am (re)placing player icon</p>

<pre><code>RelativeLayout mapLayout = (RelativeLayout) findViewById(R.id.mapLayout);
        mapLayout.removeView(playerIcon);
            RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(40, 40);
            Point playerCoords = game.getWorld().getCurrentSpace().getPosition();
            params.leftMargin = playerCoords.x;
            params.topMargin = playerCoords.y;
        mapLayout.addView(playerIcon, params);
</code></pre>