简体   繁体   中英

set the origin (x,y) of a view inside of a RelativeLayout

I have some game pawns on a screen inside of a RelativeLayout. When the user clicks the pawn I would like then to be able to drag it under there finger. I have the MotionEvent captured but can't seem to find how to adjust the orion of the pawn.

I've seen posts saying to adjust the margin but that seems questionable. I still want to do hit tests for the pawns after they've been moved and don't understand how to work with the margins in that case.

thanks!

I would recommend not using a Relative Layout at all.

A Canvas is a much better option

Or if you really want to use a layout, possibly an AbsoluteLayout is a better option

Using a layout for a game may prove unsatisfactory as you proceed. I can recommend using the free and open source game engine AndeEngine for making 2D games. The problems you have with collision detection and x,y positioning are trivially easy to implement with it. I've made 2 games and a visualization view within an app with is so far.

Check it out here:http://www.andengine.org/

You can download the demo app to your android device and see its out-of-the-box capabilities. (They include Sprites, sound, animation and more.)

This one game I made with it. https://market.android.com/details?id=com.plonzogame&hl=en

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM