I code a game like battleship. When a player has put a ship on a playfield by dropping an imageView (a ship) I would like to be able to mark this ship being hit with putting a imageView indicating that later on.
This is my layout so far (setup to configure the ships):
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:weightSum="1"
android:background="@drawable/background_blue"
android:layout_gravity="top|center_horizontal" >
<ImageView
android:id="@+id/imageSetzeSchiffe"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal|top"
android:src="@drawable/image_schiffe_setzen"
android:contentDescription="@string/startscreen"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true">
</ImageView>
<ImageView
android:id="@+id/imagePlayfield"
android:layout_width="300dp"
android:layout_height="280dp"
android:src="@drawable/image_playfield"
android:contentDescription="@string/startscreen"
android:layout_gravity="left|bottom"
android:layout_below="@+id/imageSetzeSchiffe"
android:layout_alignParentLeft="true"/>
<ImageButton
android:id="@+id/buttonDrehen"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/button_drehen"
android:contentDescription="@string/startscreen"
android:layout_gravity="center"
android:layout_alignBottom="@+id/imagePlayfield"
android:layout_toRightOf="@+id/imagePlayfield"
android:layout_marginLeft="24dp"/>
<ImageButton
android:id="@+id/buttonPlay"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/button_play"
android:contentDescription="@string/startscreen"
android:layout_gravity="center"
android:layout_alignBottom="@+id/buttonTurn"
android:layout_toRightOf="@+id/imageShipCarrier"/>
<ImageView
android:id="@+id/imageShipCarrier"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/image_ship_carrier"
android:contentDescription="@string/startscreen"
android:layout_gravity="center"
android:layout_centerVertical="true"
android:layout_toRightOf="@+id/buttonDrehen"/>
<ImageView
android:id="@+id/imageShipCruiser"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/image_ship_cruiser"
android:contentDescription="@string/startscreen"
android:layout_gravity="center"
android:layout_alignTop="@+id/imagePlayfield"
android:layout_toLeftOf="@+id/imageShipGunboat"
android:layout_marginRight="31dp"
android:layout_marginTop="19dp"/>
<ImageView
android:id="@+id/imageShipGunboat"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/image_ship_gunboat"
android:contentDescription="@string/startscreen"
android:layout_gravity="center"
android:layout_alignTop="@+id/imageShipCruiser" android:layout_alignRight="@+id/buttonSpielen"
android:layout_alignEnd="@+id/buttonSpielen"/>
<ImageView
android:id="@+id/imageShipSubmarine"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/image_ship_submarine"
android:contentDescription="@string/startscreen"
android:layout_gravity="center"
android:layout_above="@+id/buttonSpielen" android:layout_alignRight="@+id/buttonSpielen"
android:layout_alignEnd="@+id/buttonSpielen"/>
<ImageView
android:id="@+id/imageShipSpeedboat"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/image_ship_speedboat"
android:contentDescription="@string/startscreen"
android:layout_gravity="center"
android:layout_below="@+id/imageShipCruiser" android:layout_alignLeft="@+id/imageShipCruiser"
android:layout_alignStart="@+id/imageShipCruiser"/>
</RelativeLayout>
For drag and drop, I use an touchListener (for the ships being clicked) and dragListener for the drop area (here: imagePlayfield).
How can I load another imageView (not within the xml/layout) later on and put it over a ship being set?