Is there any way to apply an XSL stylesheet to the layout XML files in res/layout/ at build time so the resource compiler sees only the transformed output instead of the actual files on the hard drive?
Why: layout_width and layout_height have no default, everything requires them, and manually specifying them for every. single. widget. is. slowly. driving. me. 开发者_C百科insane.
So... the idea I came up with was to use XSLT to automatically and transparently add layout_width and layout_height attributes having a value of "wrap_content" to any tag that lacks them at build time. I'd be happy, and ADT will never know the difference. :-)
Is there any way to apply an XSL stylesheet to the layout XML files in res/layout/ at build time so the resource compiler sees only the transformed output instead of the actual files on the hard drive?
Customize your Ant build.xml
file to do whatever you want. Ant even has an xslt
task you can try to use.
layout_width and layout_height have no default, everything requires them
They sometimes have defaults, depending on their parent. TableLayout
gives all children fill_parent
and wrap_content
for width and height, respectively. TableRow
gives all children wrap_content
for both width and height. Those defaults can be overridden in your layout XML file if needed.
i would suggest a java program or a script, that will require you to abandon the 'old ways' of right click on the android project in eclipse and clikc on export as... you will have to use things like mavno ant to build your application, not so bad if you ask me... this way before your run the appt to gather your resoures you can you run your custom program that checks your xml for missing layout_width and laout_height completing the ones missing.
Another way is to use th same programe from within eclipse before you export your application.
In any case default width and height if you ask me is a bad practive, what will be your default ? wrap_content ? usually you do have to specify them in one way or another. But you have some ideas her if you still wants your default :-)
精彩评论