I am new to Android Development, so what is meant by child in the below paragraph....
A ScrollView is a FrameLayout, meaning you should place one child in
it containing the entire contents to scroll; this child may itself be
a layout manager with a complex hierarchy of objects. A child that is
often used is a LinearLayout in a vertical orientation, presenting a
vertical array of top-level items that the user can scroll through.
https://developer.android.com/reference/android/widget/ScrollView.html
In android (and most other technologies), views can have subviews, aka "children". Most views can have children and can be a child of a parent view. It's kind of like a "tree".
The most obvious feature of being a child of some other view is that the child moves with the parent view. Another feature is that the child is in the coordinate space of the parent view.
Your paragraph here basically says you can only put one child view in ScrollView and it is usually a LinearLayout. But don't be fooled! This child can have its own child views.
Gaurav i think this is what you looking for, you need to use only one LinearLayout tag inside ScrollView tag, if you are using more than one LinearLayout than it will show error. If you want to use more LinearLayout tag you can use them inside LinearLayout tag which is inside ScrollView tag. May be this will help you.
You need to understand the general concept of child and parent . Simply you can think of the real life relation between parent and child.on the hierarchy parents are toplevel and child is below.so when you come to android layout parent is container and child is the content.
Related
I understand the advantage of a FrameLayout when you need to add multiple children to it. But what is the point of adding a FrameLayout as your root element when you only have one child (lets say a TextView)? I mean why wouldn't you simply set that single child (e.g. the TextView) as the root of your layout?
A FrameLayout is - as the name implies - a Layout. It inherits from ViewGroup which is used for positioning and aligning child views.
Of course you would be able to set a TextView alone in your Layout xml. But what are you going to do if you want it to be centered?
Then it would make sense to use a FrameLayout as a sort of "Wrapper" around your TextView which lets you position it the way you want.
Is there a way to have more than one child in scrollview using a constraint layout? I'm new to coding so any help would be appreciated. I am using the latest version of android studio.
It's impossible to add more than one child into ScrollView / HorizontalScrollView / NestedScrollView
Google doc says next:
A view group that allows the view hierarchy placed within it to be scrolled. Scroll view may have only one direct child placed within it. To add multiple views within the scroll view, make the direct child you add a view group, for example LinearLayout, and place additional views within that LinearLayout.
android developers
Just wrap the children into a FrameLayout or so.
-> ScrollView
\-> FrameLayout
\-> Child 1
\-> Child 2
\-> Child 3
If you want them to be one below each other use a LinearLayout and set android:orientation="vertical".
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
Let me explain the scenario that I want to achieve:-
Consider the below as the Layout I have inside a Parent_Linearlayout:
[Linear Layout] (Fill_Parent, Wrap_Content)
[ScrollView]
Activity's setContentView is set to the Parent_Linearlayout
In the application, when a condition is met, I want the Scrollview to be removed from the screen and instead put another View in its place.
I've been able to do this, & when I remove the ScrollView, I'm applying translate Animation to it so that it seems as if the View has gone to the top -before removing it.
But when the animation occurs, the ScrollView translates OVER the Linear layout present above it.
How do I restrict it, so that the scrollview does not go over the linear layout, but disappears at the base of the Linearlayout. I want the linearlayout to always stay visible..
I've been trying to do this from quite some time, but I've not been able to get desired results..
Could someone kindly help me out here??
I don't quite understand your description of your layout, but the Android view system is drawn based on the ordering of the views in the hierarchy. Views added later to a parent are drawn after those added earlier. So if you always want the LinearLayout to be drawn on top of the ScrollView if/when they overlap, then declare or add the ScrollView object to its parent before the LinearLayout object.
In thinking more about this, I suppose the ordering here is important because you want the ScrollView to be placed below the LinearLayout in the parent of both of these views. Putting the ScrollView first (and thus having it painted first) would then put it above the other LinearLayout, which isn't what you want.
There are various ways to achieve what you want. For example, you could use a RelativeLayout as the parent of the views, then the ordering is not important.
Alternatively, you could place the ScrollView inside another LinearLayout (and that LinearLayout would be the second child of the overall parent layout). Then when you animate the ScrollView, it would be clipped by its immediate parent, which I believe would give you the effect you're looking for (make sure that setClipChildren() is set to true on this new intermediate LinearLayout, which it is by default, otherwise it won't clip the ScrollView as it animates out of it). Note that this approach would necessitate different animation values, since you are now animating the view outside of its parent (the new LinearLayout).
I am confused about the difference between LinearLayout, RelativeLayout, and AbsoluteLayout.
Could someone please tell me the exact differences between them?
LinearLayout means you can align views one by one (vertically/ horizontally).
RelativeLayout means based on relation of views from its parents and other views.
ConstraintLayout is similar to a RelativeLayout in that it uses relations to position and size widgets, but has additional flexibility and is easier to use in the Layout Editor.
WebView to load html, static or dynamic pages.
FrameLayout to load child one above another, like cards inside a frame, we can place one above another or anywhere inside the frame.
deprecated - AbsoluteLayout means you have to give exact position where the view should be.
For more information, please check this address https://developer.android.com/guide/topics/ui/declaring-layout#CommonLayouts
Definitions:
Frame Layout: This is designed to block out an area on the screen to display a single item.
Linear Layout: A layout that arranges its children in a single column or a single row.
Relative Layout: This layout is a view group that displays child views in relative positions.
Table Layout: A layout that arranges its children into rows and columns.
More Information:
FrameLayout
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.
Child views are drawn in a stack, with the most recently added child on top. The size of the FrameLayout is the size of its largest child (plus padding), visible or not (if the FrameLayout's parent permits).
RelativeLayout
A RelativeLayout is a very powerful utility for designing a user interface because it can eliminate nested view groups and keep your layout hierarchy flat, which improves performance. If you find yourself using several nested LinearLayout groups, you may be able to replace them with a single RelativeLayout.
(Current docs here)
TableLayout
A TableLayout consists of a number of TableRow objects, each defining a row (actually, you can have other children, which will be explained below). TableLayout containers do not display border lines for their rows, columns, or cells. Each row has zero or more cells; each cell can hold one View object. The table has as many columns as the row with the most cells. A table can leave cells empty. Cells can span columns, as they can in HTML.
The width of a column is defined by the row with the widest cell in that column.
Note: Absolute Layout is deprecated.
LinearLayout : A layout that organizes its children into a single horizontal or vertical row. It creates a scrollbar if the length of the window exceeds the length of the screen.It means you can align views one by one (vertically/ horizontally).
RelativeLayout : This enables you to specify the location of child objects relative to each other (child A to the left of child B) or to the parent (aligned to the top of the parent). It is based on relation of views from its parents and other views.
WebView : to load html, static or dynamic pages.
For more information refer this link:http://developer.android.com/guide/topics/ui/layout-objects.html
LinearLayout - In LinearLayout, views are organized either in vertical or horizontal orientation.
RelativeLayout - RelativeLayout is way more complex than LinearLayout, hence provides much more functionalities. Views are placed, as the name suggests, relative to each other.
FrameLayout - It behaves as a single object and its child views are overlapped over each other. FrameLayout takes the size of as per the biggest child element.
Coordinator Layout - This is the most powerful ViewGroup introduced in Android support library. It behaves as FrameLayout and has a lot of functionalities to coordinate amongst its child views, for example, floating button and snackbar, Toolbar with scrollable view.
Great explanation here:
https://www.cuelogic.com/blog/using-framelayout-for-designing-xml-layouts-in-android
LinearLayout arranges elements side by side either horizontally or vertically.
RelativeLayout helps you arrange your UI elements based on specific rules. You can specify rules like: align this to parent’s 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 of views along Z-axis. That means that you can stack your view elements one above the other.