Just a beginner question about what is the equivalent to FrameLayout (Android) in Xamarin.Forms?
FrameLayout is a control that is designed to contain a single child but can optionally have multiple children that are controlled with gravity or what works similar to zindex.
I don't think there is a direct map from xamarin.Forms to Framelayout.
if your just looking for a page level container for a single control there is:
Frame-An element containing a single child, with some framing options. Frame have a default Xamarin.Forms.Layout.Padding of 20.
ScrollView-An element capable of scrolling if it's Content requires.
If your looking for a Multiple Item Container the options are:
Grid -A layout containing views arranged in rows and columns.
RelativeLayout -A Layout that uses Constraints to layout its children.
StackLayout - A Layout that positions child elements in a single line which can be oriented vertically or horizontally. This layout will set the child bounds automatically during a layout cycle. User assigned bounds will be overwritten and thus should not be set on a child element by the user.
see:https://developer.xamarin.com/guides/cross-platform/xamarin-forms/controls/layouts/
However none of these support the Z-Index like ability of FrameLayout the best option at the moment is a Grid with a single element. The children will layout from back to front in the order they are in the Grids.Children stack.
What is the exact use of FrameLayout in Android?
Where can we use it?
What is the difference between Frame and Relative layout?
LinearLayout arranges elements side by side either horizontally or vertically(rows vs columns).
RelativeLayout is a layout manager that helps you arrange your UI elements based on some rule. You can specify things like: align this to parents left edge, place this to the left/right of this elements etc.
AbsoluteLayout is for absolute positioning i.e. you can specify exact co-ordinates where the view should go.
FrameLayout allows placements along Z-axis. That is you can stack your view elements one above the other.
As per my opinion
RelativeLayout can use to make sure views lineup correctly in relation to each other.
FrameLayout is very similar except it's only using gravity to put display it's views (with no relation).
For more information, please check this official page:http://developer.android.com/guide/topics/ui/declaring-layout.html#CommonLayouts
there are many question about "FrameLayout". But i need the exact use of this different from LinearLayout, RelativeLayout. And in a project when we have to use this?
FrameLayout is designed to block out an area on the screen to display a single item. Generally, FrameLayout should be used to hold a single child view, because it can be difficult to organize child views in a way that's scalable to different screen sizes without the children overlapping each other. You can, however, add multiple children to a FrameLayout and control their position within the FrameLayout by assigning gravity to each child, using the android:layout_gravity attribute.
LinearLayout arranges elements side by side either horizontally or vertically(rows vs columns).
RelativeLayout is a layout manager that helps you arrange your UI elements based on some rule. You can specify thisngs like: align this to parents left edge, place this to the left/right of this elements etc.
Check these links
http://logc.at/2011/10/18/when-to-use-linearlayout-vs-relativelayout/
http://developer.android.com/reference/android/widget/FrameLayout.html
I have read many articles regarding layout, but I am still quitely confused. My questions are:
When to use relative layout? Example?
When to use table layout and why we can't use it instead of relative layout?
When to use linear layout?
I just need brief answers.
When use which layout?
I think It depends on your UI, and most important thing that how you create optimized layout.
From definition : -
LinearLayout – designed to display child View controls in a single row or column. This is a very handy layout method for creating forms.
RelativeLayout – designed to display child View controls in relation to each other. For instance, you can set a control to be positioned “above” or “below” or “to the left of” or “to the right of” another control, referred to by its unique identifier. You can also align child View controls relative to the parent edges.
TableLayout – designed to organize child View controls into rows and columns. Individual View controls are added within each row of the table using a TableRow layout View (which is basically a horizontally oriented LinearLayout) for each row of the table.
References :
Creating Efficient Layouts
Common Layout Objects
And most important Hierarchy Viewer
at first there is some confusion about these layouts but as you start playing with these three layouts u will get idea where to use what.. I worked on relative-layout the most.
Consider i want to use a widget always at bottom of screen then with table or linear layout this is not possible always.. without feeling screen other two can not make item at bottom but relative can do.use of any type of layout depends on your screen requirements.
I started out using relativelayout. But recently I've switched to using mostly linearlayout.
The reason is kind of hard to explain, but take this as an example: Say I want a layout that has two images centered in the middle of the screen. Both images should take up 1/4 of the screen width and 1/4 of the screen height. This is impossible to do with relativelayout assuming you want it to work exactly the same on all devices. But you can do this with Linearlayout. By creating vertical and horizontal parents, you can create "boxes". To accomplish this you must learn about weigthsum and weigth. Parent layouts should have the weigthsum attribute and children should have the weight attribute.
Anyway, my point: Relativelayout is easy to use but it's also deceptive. You may think that your layout will look exactly alike on all device, but most likely, they won't look alike. The reason for this is:
With relativelayout you must define size with either dp or px(assuming you don't fill parent or wrap content).
Different devices have different aspect ratios.
I hoped that helped in terms of understanding relative and linearlayout.
What is the difference between linear and relative layout?
LINEAR LAYOUT ::
In a linear layout, like the name suggests, all the elements are
displayed in a linear fashion
Either Horizontally or Vertically and this behavior is set in
android:orientation which is an attribute of the node
LinearLayout.
Linear layouts put every child, one after the other, in a line,
either horizontally or vertically.
Click here ---- for --- Android Docs reference for linear layout
RELATIVE LAYOUT::
In a relative layout every element arranges itself relative to other
elements or a parent element.
It is helpful while adding views one next to other etc
With a relative layout you can give each child a LayoutParam that
specifies exactly where is should go, relative to the parent or
relative to other children.
Views are layered on top of each other in relative layout
Click here ---- for ---Android Docs reference for Relative layout
Optimization::Have a look at Optimizing Layout Hierarchies
The Fewer Views, the Better::
The number one goal for your layouts should be using the fewest number of Views possible. The fewer Views you have to work with, the faster your application will run. Excessive nesting of Views further slows down your application.
A RelativeLayout hierarchy will typically use fewer Views and have a flatter tree than a LinearLayout hierarchy. With LinearLayout, you must create a new LinearLayout every time you want to change the orientation of your views – creating additional Views and a more nested hierarchy. As a result, it is recommended that you first use RelativeLayout for any layout that has any complexity. There is a high probability you will reduce the number of Views – and the depth of your View tree – by doing so.
Linear layouts put every child, one after the other, in a line, either horizontally or vertically. With a relative layout you can give each child a LayoutParam that specifies exactly where is should go, relative to the parent or relative to other children.
From Android developer documentation: Common Layout Objects
LinearLayout
LinearLayout aligns all children in a single direction — vertically or horizontally, depending on how you define the orientation attribute.
RelativeLayout
RelativeLayout lets child views specify their position relative to the parent view or to each other (specified by ID)
difference is simple: in LinearLayout we arrange stuff in linear manner (one after another), and in RelativeLayout we can place stuff anywhere on screen.
=> Linear Layout is arranged as a list.
Rest they are similar in functionality.
One of the characteristic feature of LinearLayout in Android is use of a property called Weight, which app can specify using android:layout_weight.
This attribute assigns an "importance" value to a view in terms of how much space it should occupy on the screen.
On the other hand, RelativeLayout do not support weight or in other words, RelativeLayout does not pay attention to android:layout_weight. That's a property of LinearLayout.LayoutParams, but not of RelativeLayout.LayoutParams.
Linear Layouts
Linear Layouts are great for aligning views in rows and columns.
They are a good way to divide up one place using layout weights that will expand or shrink views depending on the size of the Display.
Relative Layouts
Relative Layouts are great for positioning elements relative to one another.
For example putting B below A or putting C in the lower left hand corner.Check the Screen shoot
Relative layout also make it easy to overlap views. For Example : view A is overlapping view B. Check the Screen-Shoot
RelativeLayout is more flexible than LinearLayout but if you have proper knowledge about LinearLayout you Can use that too.
For LinearLayout every attribute has a significant position hardcoded by the developer.
For RelativeLayout you can change the position by relating with others attribute.
The following link should explain visually how the layouts work "Visually"
http://www.droiddraw.org/
Add some components to the window and mess with layouts to see what happens this is how I learned what each one does.
In the relative layout ,all the content in the layout page is related to other contents in the example_layout.xml page
In the case of Linear Layout the elements are displayed in the linear format
The difference between linear and relative layout in android is that in linear layout, the "children" can be placed either horizontally or vertically, but, in relative layout, the children can be placed with relative distance from each other. This is the difference between linear and relative layouts.