android - Dynamicially set an imageView over another imageView -


i code game battleship. when player has put ship on playfield dropping imageview (a ship) able mark ship being hit putting imageview indicating later on.

this layout far (setup configure 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 , drop, use touchlistener (for ships being clicked) , draglistener drop area (here: imageplayfield).

how can load imageview (not within xml/layout) later on , put on ship being set?

use frame layout images stacked on each other, move elements or down in stack, becomes visible or hide alternatively.


Comments

Popular posts from this blog

python - Healpy: From Data to Healpix map -

c - Bitwise operation with (signed) enum value -

xslt - Unnest parent nodes by child node -