I would like to have different activity.xml files for different orientations.
I have created a another folder with name layout-land. When I copy and paste the activity_main.xml file into it, then screen size is automatically getting oriented to landscape.
But after doing this, code assist is not working. Its showing the following error when I press ctrl+s
Content assist not available at the current location
what is the reason for this? Did I do anything wrong for creating different layouts for both orientation?
This sounds like an IDE-specific issue more than anything. The way you're doing it is correct. Assuming you a layout with the same name in as the other inside of layout-land, you should be good to go. Just give it a whirl.
Sounds like an Eclipse error to me (Googling "Content assist not available at the current location gives me a lot of hits); try running your application on a device and it will most likely work. It doesn't sound like you've done anything wrong.
Related
Is there a quick and easy way to see how my application will look on different screen sizes and shapes? Currently, I'm going into the AVD manager, editing my device definition, and then launching a fresh emulator. It takes maybe ten minutes for each one.
They layout is defined entirely from resource files. I don't actually need to execute the app. Is there a faster way to do this?
Edit: I should add: there are some custom widgets in the app.
While looking at a layout open the "Design" tab or open the "Preview" tab on the side. On the top of the window you will see a list where you can change the layout and orientation.
May not solve your entire issue, but it's a good to know.
If you want to have a preview of a static page (not rendered at runtime, like recyclerview), you could use android studio to do that.
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.
I want to show two extra textfields when my application is shown in landscape. I know I can do this by copying my original layout to folder layout-land and just add 2 fields, but that way I need to maintain 2 versions of my layout file, the original one and the one copied to folder layout-land. What I actually want is just add two textfields without the need for maintaining 2 copies of a layout file. Can you do that ?
thanks, Steef
The idea which I've thought is may or may not be correct. My idea is to check the device orientation in class file and when the layout is landscape, just manipulate your layout or simply mean just add two text field at that time. Hopefully! it will work.
Happy Coding!!!
Im beginner but i might have some idea. If you dont want to have 2 layouts file, there is second options- make styles.xml for portrait and land and you can write style which set visibility. Try something like that.
I have a complex project with many layouts (approx 40) and to reduce duplication, I am using a lot of includes.
I have an activity layout in layout-xlarge-land which includes another layout (layout B) which itself is just a set of more includes in a LinearLayout.
My emulator is set to XLARGE and landscape and sure enough, it picks up the activity layout. I've hard coded the activity title in the layout so I can confirm which one is being used.
The problem is that if I put layout B in layout-xlarge-land, the ADT will not preview my layout and gives a "cannot render" error. if I move layout B to res/layout (i.e. with no qualifiers) it works.
My understand is that Android will look for a layout in the qualified folder first then, if not found, use the one in the unqualified folder.
It's a problem because layout B should be different for the various resolutions and orientations.
Am I misunderstanding something or is this a quirk of the ADT/Android? If a quirk, any workarounds?
res
layout
layout-xlarge-land
activity_layout.xml <---- correctly loaded
layoutb.xml <---- "cannot render"
res
layout
layoutb.xml <---- renders OK
layout-xlarge-land
activity_layout.xml <---- correctly loaded
[EDIT] I'm using IDEA but don't see any relevance to the IDE.
[EDIT]
From the IDEA log
s.android.uipreview.RenderUtil - InflateException: You must specifiy a valid layout reference. The layout ID #layout/data_panel_all_views is not valid.
This confirms that ADT is looking in res/layout.
Taking a look at How Android Finds the Best-matching Resource, it tells that you can provide multiple qualifiers and how the best layout is chosen, so in the case you are sorting qualifiers well (which looks like you're doing, as the activity_layout is correctly loaded), try applying less qualifiers and seeing if those includes are working. Otherwise, you could think about the dirtiest solution: creating different layoutb's for each resolution and storing them in the same folder. That would mean each activity_layout would load it's correct file.
Good luck!
This was weird. One of the things I did was to restart IDEA which didn't resolve anything.
I've just rebooted my PC to install some updates and since starting IDEA, it's working as expected.
I've seen some issues with layouts which were fixed by restarting Eclipse. The common element is ADT so I suspect some flakiness in there.
I developed a application. In that i get GUI perfect in portrait, but when i tern my emulator(pressing Ctrl+F11) some text and buttons will be miss ordered. i searched so many sites but i am not get the solution.
Please any one give a solution.
Thank You.
For solving these problem you should make two layout for different different
1-: create a new folder in side the resource is layout-land then put your layout for landscape in this folder.
2-: another one is use for portrait mode its put in layout folder.
you can create your application to support landscape mode by creating different layouts.
simply you can create a folder in your res folder like this -> /res/layout-land and copy your layouts and make necessary changes(for landscape) to it.
please read the documentation for further details
tutorial