Fragment Layout not corresponding to preview - android

So, first of all I'm very new to Android so this may be a very dumb question, but..
I have in my mainActivity layout a viewPager which calls some fragments of different type (I have made 4-5 xml layout displaying different informations)
Despite I created all the layout basing on weighed LinearLayout to maximize compatibility, in the preview the visibility seems perfect in each device I selected, but once I load the application on my phone, the layout has bizarre behavior.
Here an example (preview vs. screenshot from my device)
I'm not sure about where I made the mistake, I would like to know:
1) What happened
2) What cause this behaviour
3) How to fix it (a link with a guide would be very welcome)
Thanks very much!

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.

Xamarin Android FlyOutMenu by Garuma - Multiple Screens

So I'm using Garuma's FlyOutContainer class in my project (http://blog.neteril.org/blog/2013/04/19/fly-out-menu-xamarin-android/)
But I'm having trouble using the menu to change the content layout. Whenever I remove a view from the content layout and inflate another, it draws the entire content layout at 0, 0 so when the menu layout closes, it drags the content layout past the left edge of the screen as well!
I've been looking for answers and fiddling with this for days now, so I thought I'd ask if anyone here has run into this issue and fixed it as well.
Alternatively, a layout that I could hold static to switch between several other layouts might work as a solution, I just haven't been able to find one that could do so that worked with this FlyOutContainer.
Thanks in advance for any and all replies!
-Sibley
I suggest using the DrawerLayout which Google supplies in the Support.v4 packages, which shows the standardized version of the FlyOut/Sliding/NavMenu which has been implemented in various ways previously, including FlyOutMenu.
I have a sample showing both DrawerLayout and SlidingPaneLayout in my GitHub repo.
One thing to notice is that SlidingPaneLayout is not meant for navigation, while DrawerLayout is. The former is meant as a responsive design, where a Pane's visibility is toggled in portrait mode, while always visible in landscape mode.

tablet/handset layout structure with fragments

In this article http://developer.android.com/guide/practices/tablets-and-handsets.html
we use res/layout/main.xml with one fragment for handsets and res/layout-large/main.xml with two fragments for tablets. We must check if second fragment is in the layout to define if app runs on tablet or on phone.
I have 4 layout (2 for phone and 2 for tablet):
layout-port
layout-land
layout-sw600dp-port
layout-sw600dp-land
I check screen orientation to define if display is in portrait or landscape mode and check if layout contains a fragment to define if it is tablet or phone.
Is there any better way to work with layouts and fragments?
Is it possible to use one layout if we have two fragments for example http://i.stack.imgur.com/FtzKs.png and if a phone display doesn't fit both of them to show only the first one?
Thanks in advance! :)
What you're showing there is indeed possible! That is something called a Master Detail Flow (if you're developing in Eclipse with adt, check out he new activity wizard, which provides this as a template option).
This layout is basically just two fragments inside an activity (or, now, as of android 4.2, they can be nested in another fragment as well!) that interact with each other in a certain way. To create the layouts you linked to, one would detect whether the device is a phone or a tablet, and then set the visibility of the two fragments in different situations accordingly.
You will find a number of methods for detecting screen size here, whether you want to use screen size in inches, pixels, or the manufacturers' default categories.
And properties like visibility and sizing can be set programmatically using Layout Params and its various subclasses.
In any particular case, whether you choose to use multiple layouts to support different screen sizes or to do more of it programmatically is up to you. Personally, I think that it is always a good practice to design your code modularly and then use layouts to put all the pieces together (it'll save you a lot of headaches down the line if you decide you want to change things up). But either way, supporting more devices will always require more code, and there are no two ways around that...one of the curses of android development :P

Issue with android tablayout switch tab

I am a new android developer, just tried something with Android Tablayout.
There are two tabs and one tab has a GridView and the other one has a DatePicker.
I created an activity and layout for each tab.
The problem is that when I switch to the gridView, the background is not refreshed, and the images are just drawn over the DatePicker, so through images, the DatePicker still can be seen. It really bothers me.
What should I do to have a clean background for imageView?
Steve
There is something wrong with your layouts if you are seeing that behavior. Here is a sample project showing multiple activities as the contents of tabs. Here is another sample project that takes the more efficient approach of just using Views as the contents of tabs. Hopefully, by examining these, you can see where things may be going wrong with your layouts.

Categories

Resources