To my understanding, the content file is just the xml files contents...but in a separate file. Whats the point?
I've seen
What is the role of content_main.xml in android studio 1.4?
and there doesn't seem to be much documentation about content_XXX.xml, so I was wondering, why did the new update include the default creation of this file?
Why divide the code into two files, why not just put all of the contents in its own xml file, I've tried it...and it works. I fail to understand why the content_main file is generated on creation of a new project.
Can someone give me a list of benefits of why I should be using the content file?
Thanks,
Ruchir
activity_main.xml is used to display coordinatorLayout, tabLayout, floatingActionButton, viewPager etc.
content_main.xml is used to display your stuff i.e. what you want to display to users.
for more details check my answer here.
Update after conversation in comments below: The point of doing this is to bring in more organization in the code. We can always go forward with the old way of putting everything in one file. Android Studio is just giving us a start with keeping the layouts in a more organized way to allow easy comprehension of code and reuse wherever possible, by segregating related stuff.
Related
I have to make a new design for an Android App, but I only have to create the visual part (native Android). The app logic would be created by another guy based on what I present to him.
My question is? How would this be managed correctly? Do I have to make the XML's of each layout? How could I show the other person my progress?
What things should I consider when doing this?
Thanks
You need to mock the app first (create a prototype) as suggested by NoChinDeluxe. Then if you guys go ahead and decide to code it, the answer to your problem is separation of responsibilities. As Jeffrey said UI work is not only about layouts, but code as well. What I would suggest is that you and the other guy get together first and define some contracts (interfaces) that will allow you guys to split the work and work in parallel. Therefore, he can create the business logic of the app without worrying about the UI implementation. You, on the other hand, will have to mock that business logic he's implementing at the beginning so it doesn't block your UI work.
you could create layout XML files for all the Activities/screens, using resources (icons, etc as suggested by #NoChinDeluxe). However since you'd want to run the mock app, you might want to also create a "throw-away" Activity that allows you navigate to different screens of the app. Here you can add a number of buttons and when you click on each button, your app shows a specific activity. This way, you will be able to show your colleague all the screens you have created. I hope this helps.
This may not be what you want to hear, but creating Android layouts isn't a design task. They are closely tied to the code, and the design of them is going to depend on how the engineer chooses to implement the app.
Here's an example. You might have a grid with 4 cells. You could use a RelativeLayout, a LinearLayout, or GridLayout, or a GridViewLayout. Which will use choose?
I'd suggest providing your engineer with mockups and graphical assets where required. Let him / her take those and create the layouts. If you want to create layouts as a (visual-only) reference for engineering, great, but it's certainly a non-optimal tool for that task.
Things You will consider when doing visual part:-
You have to work on the resource folder of your application
Layout : All Layout you have to prepare.
Drawable : Images and drawable .xml.
Inside Values folder you will find
dimen.xml : For different devices dimen you can set.
string.xml : You can store string for hint or other purpose.
style.xml : For designing or theme or custom design.
color.xml : Color which are going to used in the application.
I'm learning to develop android apps and in the process I realized that there two ways to get a job done. Using xml or normal code. Suppose I want to change the position of a button, I'll be doing it in xml using align left/align centre etc., This will be done in the XML file. If I want to achieve the same through code, where should I place the code ? Inside which class ?
There are two aspects to your question that I understand.
1. Creating a whole layout file dynamically (without XML).
2. Creating a layout through XML and changing the components positions and properties dynamically through your activity file.
Now, it's upto the developer what he wishes to choose.
To help you further, please view this video link posted by the Android team.
It's all about layouts and includes how to layout apps using Java, not XML. However, you are warned that the android team wants you to use XML.
The code will be placed in the same class as the class where you reference your xml code. Do a read up in your android docs for insight.
I don't know whether i am asking the right question or a wrong one.
it may sound foolish but still i feel to clear my basic doubts.
the question is:
i have three different layout files for a single activity.
depending upon the purpose for which the activity is started, it will take one of these layout files as its content.
these layouts have various fields in common.
i have a question that in these different layout files can i have the same "id's" for the common fields.
for ex: i have a save button for all the three layouts.
in all those three layout files..... can i have (For the button)
android:id="#+id/save_button"
the same ID attribute in all the three files.
i require this because i have too many elements(components) in my layout files.
if they can be identified with common names (as they serve the same purpose in their respective layouts) there would be very less names/ids to remember, which will make my program easy to be readable and less things for me to remember.
else i will have to write the same code for components with same functionality.
thankyou in advance.
your answers will help me clear my doubts. please correct me if i am moving with wrong concepts.
Not only is this allowed, but I would encourage it. Using the same id across files allows you to create new layout files without having to change any of the code referencing the button. As long as the id is descriptive of what it relates to, then it shouldn't cause any problems.
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.
When I am in a Java class file, I can get context info of a certain method/attribute/etc. (in IntelliJ, this shortcut is Ctrl+Q), which is basically a short help file describing what that element does. Look at the image 1.
But when I am in an XML file, I cannot get any contextual info on any element. Look at the image 2.
How should I enable it? Do I have to download some additional Android doc (javadoc?) file?
For Android code support in Eclipse, you might want to checkout http://android-developers.blogspot.com/2011/06/new-editing-features-in-eclipse-plug-in.html.
In particular :
XML editing has been improved with new quick fixes, code completion in more file types and many “go to declaration” enhancements.
basically a short help file describing what that element does
FYI: It's called Javadoc.
For the xml:
Go to Window, Show View, Other, General, Properties.
Then, when you have opened an Android xml, you can switch to the Graphical Layout. Clicking on an element will show you it's properties in the property view. Hovering over the elements there at least will give you contextual information.
As CrazyCoder suggested, there is no way to get such contextual info because of the lack of sources to fetch such info from. Until better times...