简体   繁体   中英

New to android, have a question about layouts in general

I'm making a new application and its basically filled with information about Warcraft.

I have similar apps on my phone that have similar information and when I looked inside their .apk they only had like 10 layouts.

The app that I am making already has 5 layouts and it seems like I will need about 50-60 layouts.

So now my question is it normal to have that many layouts? Or do I have to learn to make one general layout and keep reusing it? For example, like if I need to display information about a topic for instance the classes in warcraft which are 10 different classes with 2-3 different guide pages on average for each class, would I need to make a different layout for each page or is their a better way of doing it?

I would really appreciate any input/suggestions.

What I recommend is having one layout for every type of screen (basically one per Activity) and use Java to fill in all of the info. Use getResources().getString(int id) and pass something from R.string. That means you need to keep all of your information in a strings.xml file in your values folder (located in /res/values). List all of your views in the layout XML file and then find them by ID and set their values.

It's best to keep all of your string resources in a separate XML file and not hard code them into the layout (otherwise it's a pain to replace every instance of a word you realized you misspelled or something). If you don't know how to write XML, that's okay since there are tools in Eclipse, but I HIGHLY recommend learning it.

You can re-use layouts without any problems. In fact for maintaining the code it is a very good idea to do so. No one wants to maintain 50+ layouts and associated code.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM