Fragment Transactions with scrollview - android

You have an Activity A --> display a fragment B (scrollView), on next button you have fragment C replaced with relative Layout. But the view is not replaced.

ScrollView Defines as follows :
"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."
-ScrollView is not a base view hence wrapping the scrolling in base views like (Linear Layout,RelativeLayout Can solve your problem

Related

Outer ViewGroup attributes to be applied by all children of nested ViewGroup

I need to create custom viewgroup that contains children which are proceeded with the attributes of the outer viewgroup for my custom.
For example,
<ConstraintLayout...>
<CustomViewGroup...>
<RecyclerView.../>
<TextView.../>
<TextView.../>
<CustomView.../>
<RecyclerView.../>
<Button.../>
<Button.../>
</CustomViewGroup>
</ConstraintLayout>
So I need for all of these RecyclerView, TextView, TextView, CustomView, RecyclerView, Button and Button to use the attributes of ConstraintLayout like
app:layout_constraintWidth_percent
app:layout_constraintHeight_percent
app:layout_constraintTop_toBottomOf
app:layout_constraintLeft_toLeftOf
app:layout_constraintRight_toRightOf
app:layout_constraintBottom_toTopOf
etc.
And the one sense of CustomViewGroup is to be used, for example, like FrameLayout, to be the container of several fragments but without many other unnecessary extra properties (all views of these fragments should be depended only on ConstraintLayout constraints).
The main point of my own don't use the nested layouts (so that the CustomViewGroup needs to be like a fake layout).
UPDATE By virtue of Mike M. comment I need to clarify my request.
I need to have some Activity with three buttons in the top and the fragments area below. Inside this fragment area three fragments should be displayed. Two fragments are almost similar and the third is different from others. First button changes the fragment area with first fragment, second button changes the fragment area with second fragment and the third button changes the fragment area with third fragment. The first and second buttons may be proceeded with one fragment just changing some parameters of general views and the third button should displays the third fragment. In any case I don't want to have nested viewgroups to arrange views inside fragments or these viewgroup's attributes should not be used by the views inside. So that I need the solutions to make these views depend on positioning attributes of the root ViewGroup ignoring the attributes of nearest viewgroups.

Multiple children in scrollview

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".

What does child mean in an android layout?

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.

Android detect position of ViewGroup Child

So I really have two related questions on ViewGroups:
Is a LinearLayout and instance of ViewGroup? Meaning, can I call getChildAt(index) when using a LinearLayout?
Can I detect when a ViewGroup child is at the "top" of the screen (right below the action bar) after scrolling? For example, when the 3rd child is scrolled to the top
I'm working on an app that utilizes Parallax Scrolling and I'm using an open source library that has a custom View with a LinearLayout as a child and 4 TextViews as the LinearLayouts children. In their custom View class they are calling getChildAt but I can't seem to find documentation on that related to LinearLayouts so I wanted to check. And essentially I want to check if one of these TextViews are at the top of the screen. Any clairfication would be much appreciated
question 1 { Is a LinearLayout and instance of ViewGroup? Meaning, can I call getChildAt(index) when using a LinearLayout? }
answer = yes... A ViewGroup is a special view that can contain other views (called children.) The view group is the base class for layouts and views containers .. so your linear layout is a view because it extends view, and if it contains other sub views called children then it's a viewgroup.. viewgroup extends view.. Meaning YES you can call getChildAt(index) when using linear layout..
question 2 { Can I detect when a ViewGroup child is at the "top" of the screen (right below the action bar)? }.
answer YES , you can check the Z order of the children in a viewgroup(a view containing other sub views) to know its position, so probably your first child is the child below the actionbar, that's if your viewgroup (that is the linear layout) is the view content of your activity - which is always the case right? - yea..
if you want a documentation on getChildAt and viewgroups in general then look here ..
hope it helps.. let me know anything that's arising..

android - what is view hierarchy?

I'm studying android, of course I'm novice, I always read something like view hierarchy, so what exactly does this mean? what is view hierarchy? e.g.
// fragment's containing frame doesn't exist. The fragment
// may still be created from its saved state, but there is
// no reason to try to create its view hierarchy because it
// won't be displayed. Note this is not needed -- we could
// just run the code below, where we would create and return
// the view hierarchy; it would just never be used.
http://developer.android.com/reference/android/app/Fragment.html
A View inside another View creates an hierarchy, the outer view becomes the parent of the inner view and the inner view is its child. It's just nested views.
Here's an example:
You'll want to read the docs on the View class, but essentially views can be children of certain other views. You can nest views in complicated ways. This whole structure of views is referred to as the view hierarchy.
http://i.stack.imgur.com/gN6AO.png
Each view in a user interface represents a rectangular area of the display. A view is responsible for what is drawn in that rectangle and for responding to events that occur within that part of the screen (such as a touch event).
A user interface screen is comprised of a view hierarchy with a root view positioned at the top of the tree and child views positioned on branches below. The child of a container view appears on top of its parent view and is constrained to appear within the bounds of the parent view’s display area.
you can refer to this link : [
http://www.techotopia.com/index.php/Understanding_Android_Views,_View_Groups_and_Layouts_in_Android_Studio][1]

Categories

Resources