3

I am creating a simple game in android so I can create something and learn how to program in Android (I'm a noob).

Right now in my layout editor (i think thats what its called, basically the place where you can create your layout xml files) there are many sizes on the top left... which one should i target? do i need to make a separate layout for each one of them?

Thanks! R

Ryan
  • 9,821
  • 22
  • 66
  • 101

1 Answers1

1

The screen size selection is only intended to give you an impression of what the layout looks like on various screen sizes and densities. A good place to get started is Common Layout Objects and Supporting Multiple Screens.

When developing for Android, you should not target a specific screen size, but instead make layout elements fit proportionally. An exception may be x-large displays such as tablets, for which a great read is Distributing to Specific Screens. An example of getting elements to position nicely is this question.

Community
  • 1
  • 1
Paul Lammertsma
  • 37,593
  • 16
  • 136
  • 187
  • How do I do that? I am using table layout and the layout changes quite a bit on every different size I choose :( – Ryan Jul 27 '11 at 01:20
  • 1
    In addition: Just do not set fixed pixels, there is need of fixed value use `sp` or `dpi` units, never use `px`. – Nikola Despotoski Jul 27 '11 at 01:20
  • Yep, my books says that as well... so i just use a tablelayout (seems easier as i am coming from a web developer background anyway) and drop my stuff in there... but with each size change...my stuff does not align too well with my background image :( – Ryan Jul 27 '11 at 01:23
  • 1
    If you're trying to do pixel-perfect aligning, it's going to be a bit of a different story. You might want to use a [RelativeLayout](http://developer.android.com/reference/android/widget/RelativeLayout.html). I would avoid that approach, however, because screen dimensions, sizes and densities vary so much that you'll probably find elements to overlap or otherwise break the visual flow. – Paul Lammertsma Jul 27 '11 at 01:27
  • Which layout would you recommend then? – Ryan Jul 27 '11 at 01:30
  • 1
    That very much depends on how the elements should appear. RelativeLayout might be a good approach for you; I was only suggesting to avoid using it to place elements pixel-perfectly. I'd suggest looking at [Common Layout Objects](http://developer.android.com/guide/topics/ui/layout-objects.html) and deciding what works best for your project. – Paul Lammertsma Jul 27 '11 at 01:40
  • This is how my layout should look in all resolutions, which would you suggest: http://imageshack.us/photo/my-images/692/androidbox.jpg/ – Ryan Jul 27 '11 at 01:52
  • 1
    Personally, I'd go for a single vertically oriented LinearLayout, containing four horizontally oriented LinearLayouts. I'd proportionally align the individual elements using layout weights, [as suggested here](http://stackoverflow.com/questions/2698817/linear-layout-and-weight-in-android/4517358#4517358). – Paul Lammertsma Jul 27 '11 at 01:59