android is there any way to test xml file on phone - android

I need to know if there is any way that i can test my xml appearence on phone without running the whole app, i mean just the xml file without any action for anything?

No there is no direct way to check the xml without recompiling and running on device.
But you can use graphical Layout editor to check the layout on approximated screens, or can create screen similar to your screen with same DPI and size.
and check it on graphical Layout editor.
NOTE: on device XML is just XML. where as when you compile the XML it is read and transformed to a view based code that is actually your UI.

Related

android studio issue: complex Layout is not showing in design view but just as XML

I have a somewhat complex layout.xml file (353 xml lines, 16kb) with multiple nested constraint layouts. This particular xml file is only showing a blank white screen in the design tab but works well when I run it on device and emulator. I have other smaller layout files which show the design normally on android studio but it seems that there is a bug with viewing larger xml files.
Is this a known issue? I tried refreshing layout and removing android studio cache but nothing seems to work. any ideas?
I do not think it has anything to do with the code since it runs normally on device and I am not sure posting the whole xml file on SO is a good idea.
update
What I realised is that all the elements in the layout seem to be 'invisible' at the top left corner since when I hover over them the pointer turns into a hand and when I click , certain elements get highlighted in the component tree. This is a screenshot of what I am seeing:
I added android:visibility="gone" which is vital to my app. Little did I know that it also applies to the design view which I find to be really useless. I want the visibility to be gone during runtime, not on a platform where I am supposed to be tweaking the design of the UI. This is ridiculous to me.
Does anyone know If I can keep visibility="gone" but still see the design in the design view of the layout?
You can use tools:visibility="visible" for designing purposes.
It has zero effect on the view in real use.
Don't forget to keep your android:visibility="gone".
In general, use tools attributes whenever you'd like to manipulate a preview in the designer while keeping your view attributes valid for real use.
Edit:
Keep in mind that there is a huge difference between invisible and gone. More about that

Is there a quick and easy way to preview a layout at different screen sizes?

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.

How does the ADT select layout XMLs depending on device size and orientation?

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.

Android development, graphical layout?

Hi im just starting to make an app, and on eclipse i get 2 tabs. Graphical layout is one of them. I see a black cell phone screen and some buttons and text stuff to put on it. What is this for and how do i use it? Thank you
With the graphical layout you can just drag and drop items in, and the xml is the actual code. Adding things via the graphical layout will edit your code for you, and visa versa. Personally I prefer to just use the xml because the graphical layout can be a little difficult to get the results you want, and it's always useful to have a good understanding of the xml code and how it works.
Android uses XML layouts. They can be a real pain to edit. The graphical layout tab with the picture of the phone is supposed to make it a little easier.
Sometimes you still have to dip down into the XML to get things just right, but the graphical layout will at least give you a preview.
It's your Interface Builder.
It builds interfaces ;)

Android : Editing layout files issue

My application has a mobile UI and tablet UI. for tablet UI specific layouts are placed in layout-large folder.
What I noticed recently is, when I change the layout of tablet it changes the XML file of the phone xml file too which is in the layout folder.
I don't know why this happens. How to resolve this issue?? I hope it has something to do with Eclipse.
At the top of the graphical editor, you can select which layout you are editing. In no case should it edit both, though.

Categories

Resources