Dynamic vs XML layout in Android?

后端 未结 7 614
不思量自难忘°
不思量自难忘° 2020-12-06 00:57

I\'m new to Android development and have started creating my own UI. I see that you can either create it dynamically something like this (Dynamic Layouts):

@         


        
7条回答
  •  醉话见心
    2020-12-06 01:48

    Use layout XML resource files.

    First, the resource sets (e.g., res/layout-land/ in addition to res/layout/) allow you to define multiple UIs to be used in different circumstances, with the system automatically choosing the right one as needed. The equivalent in Java would be one nasty set of if or switch statements.

    Second, there are tools that can help you create those layout resources successfully. Even if the drag-and-drop GUI building of Eclipse isn't your cup of tea (e.g., you're using NetBeans), Lint will help point out flaws in your layouts, for which it will point out only a subset in the equivalent Java code.

    Third, it tends to be more terse, so if you're typing this stuff by hand, the XML will be less typing.

    Fourth, approximately 98% of all sample code you will find will use layout XML files, and approximately 98% of all UI answers you find here on StackOverflow (and other support resources) will assume that you use layout XML files. While you are free to avoid XML -- perhaps you were attacked by angle brackets as a young child or something -- you will be swimming upstream, fighting the current compared to what most Android developers do.

提交回复
热议问题