So I’m trying to write a game for android, and I have a couple of questions regarding ‘best practices’ for android dev. The game I’m writing would have some dice on the top part of the screen, which the user should be able to drag around, and on the bottom half of the screen, I need to show a list of different numbers, updating as the dice are dropped into a new location. So, what’s the best way to tackle this? I’ve coded up some sample code (which works) using a single view, and drawing the dice bitmaps and the numbers, but everything is so resolution-dependent that it bugs me. Would I gain anything by switching to an xml-defined view, and adding a dice view and a number-list view, and drawing those separately? Is there a standard or best practice that I should be following?
Thanks
It is a good practice to define a Layout in
xmlfile so that your app runs on different screen sizes..For more on why you should be using xml files, please refer to Android Design Guidelines.
When using xml file use dp for sizes and sp for text sizes, also use
wrap_contentandmatch_parentwhere ever possible.You can also make density independent pixels in your code. Please see this..