Android Studio, 能够将布局 xml 文件分组到文件夹吗?
原标题:In Android Studio, can layout xml files be grouped into folders?
In Android Studio, can layout xml files be grouped into folders?
Able to do it with the java files by creating different packages/folders, can the layout files be similarly grouped/organized?
Looking for ease of organization in my workflow when i have a ton of xml files to work with.
最佳回答
No, the files have to be in predefined folders.
Here is a link to more information on available folder names: http://developer.android.com/guide/topics/resources/providing-resources.html
问题回答
Actually, they can!
Although the steps are a bit too many, it is indeed possible to group your XML files in folders. Just follow the following steps:
Switch to Project view; you can now see all your project folders and sub-folders properly.
Backup all your layout files; at this stage you ll find them all under android/app/src/main/res/layout.
Delete the entire layout directory (android/app/src/main/res/layout). Remember to properly backup all your layout files before this step.
Right-click the res directory and select "New" and then select "Directory".
Give it a name; remember the name must be entirely lowercase. Your new directory will now appear under the res folder. Let s call this directory layouts for instance.
Right-click your new directory (layouts) and select "New" and then select "Directory". This way, we are creating a new sub-directory. We can give it any name we want, just remmber it must be completely lowercase.
You can repeat step 6 as many times as you want and keep creating sub-directories.
VERY IMPORTANT! Right click any of the sub-directories and select "New" and then select "Directory". YOU MUST NAME THIS DIRECTORY layout.
Repeat this for all sub-directories.
Move all the backed-up xml files (in step 2) to the layout directory of the folder you want to put them in.
Add the code below to your build.gradle (app) file:
sourceSets {
main {
res.srcDirs =
[
src/main/res/layouts/layout_for_fragment ,
src/main/res/layouts ,
src/main/res
]
}
}
}
Replace layouts with your sub-directory name and add as many sub-directories as are available.
Sync project with gradle files
And that s it. Pretty herculean but it can come in handy anytime. You may want to visit this link for more clarification.
I hope this helps. Merry coding!
相关问题
Very basic WPF layout question
How do I get this listbox to be maxiumum size, i.e. fill the group box its in.
I ve tried width="auto" Height="auto", width="stretch" Height="stretch"
annoyingly at the moment, it dynamicly sizes to ...
Blackberry - set position of field on the screen?
I want to position my field at specified positions.
Why is my "container" div not containing my floated elements?
I m creating a website for my schools "Math Relay" competition.
I have a "Container" div (with a white background), then a top-bar, left-bar, and right-bar div inside the container.
left-bar and ...
WPF: Grid layout - how can I get row and column of element with MouseMove or similar events, when cursor is over empty cell?
As I stated in title to this question - I have an WPF Grid based layout with two header rows and few empty ones. Grid has about 100 columns.
I am trying to achieve the situation, in which I will be ...
How to align the text to top of TextView?
How to align the text to top of a TextView?
Equivalent Android API for Swings setInsets()?
that is top of text should start be in (0,0) of TextView
<?xml version="1.0" encoding="utf-8"?>
<...
Centring a flow in Shoes
Can I center the contents of a flow in Shoes?
I know that a paragraph can be centred like:
para Centred paragrpah , :align=> center
However, this does not work with flows:
flow(:align=> ...
Overlaying with CSS
I want to load a website in an iframe, and overlay the website with some hints about the website that is shown. However, i got stuck at the point that the website has a variable passive white space at ...
How do you normally make a program look beautiful? [closed]
How can I make an Application look nice and not like an amateur pulled it together?
I mean graphic-wise.
Is there some sort of book you can read regarding beautiful program layouts, etc?
I put this ...