1

I read in some posts that it's better to define ui elements in xml and not programmatically, and also that I should use dp units inside xml, so I wonder now how can I determine which fixed values should I use ?

Let's say I want to have an ImageView with a width that is 1/3 of the screen's width. Is there an offline way to find the dp number I should specify inside the xml or should I still set the height & width programmatically ?

Tamir
  • 625
  • 1
  • 12
  • 27
  • 1
    Could you please provide a link to those posts about defining them in XML file is better? – odedta Jun 28 '15 at 09:10
  • As for your question, you need a DOM parser for that, I recommend DOMDocument. – odedta Jun 28 '15 at 09:11
  • it is not true, what can be done in xml can be done in Java *2.. all those linearLayout weights and stuff are not possible without java, so to your question, yes you need to do it the java way, use getMeasuredWidth() and divide it by 3 – Elltz Jun 28 '15 at 09:17
  • http://stackoverflow.com/questions/9827819/best-practices-layouts-on-android-programmatic-vs-xml – Tamir Jun 28 '15 at 09:30
  • http://stackoverflow.com/questions/29532974/could-there-be-any-performance-difference-between-writing-the-same-code-for-the – Tamir Jun 28 '15 at 09:45
  • I know it's possible to do using code, but found these posts that suggested to use xml... Not sure why need DOM parser.. – Tamir Jun 28 '15 at 09:47

0 Answers0