Is there any advantage or disadvantage to push fragments into layouts other than Frame layout ? And do you recommend any of it ?
I tried pushing fragment into Relative Layout and I saw that my fragment stays left-top of the screen but if i push it into Frame It works well. (Both height and width are match_parent in the inflated layout)
A fragment can be generally added to any ViewGroup according to the guidelines. But on the other hand the FrameLayout's documentation states that "Child views are drawn in a stack, with the most recently added child on top" which I guess is an advantage over the other ViewGroups for the fragment backstack
Related
I followed exactly this link at androidhive of simple tabs and created a tab layout with fragments of different heights. The tab layout is inside coordinator layout along with view pager. I have some textviews after the coordinator layout. And I want coordinator layout to take only space required by fragments, so that textviews is shown adjacent to even the shorter fragment. But using wrap_content in height of coordinator hides the fragments and only shows tab titles. If I set height to 1000dp, it shows both fragments but there is lot of blank space between smaller fragment and textview. How and what should I set height to get desired result?
I will paste code if required.
I currently have this situation with smaller fragment, and I want the "FOUR" to be just below "ONE" of fragment. If I set height of coordinator layout to wrap content, no fragment is shown at all.
I have a Activity with 4 fragments. Each fragment consists of a listView. The bottom Fragments are not shown when the above fragments has data that fills up the screen.
Take a look at your Activity's root layout.
Your top fragment's heigh is probably match_parent.
Divide the layout on the parts you need (use layout_weight for example or height in dp) and make one below another.
After having been introduced to Android development and creating a few basic applications, I have begun splitting activities into fragments for reusability. However one thing that I'm still slightly confused about is how the layout of the main activity(which holds the fragments), is affected by the layouts defined for fragment activities and vice versa.
While I believe that the layouts would affect each other based on definitions of height and width for each fragment, the number of fragments in an activity, etc. However Im not sure if there are other rules I am unaware of and I want to know if the layouts specified for the fragments directly affect the way the way the layout of the main activity displays.
For example, the main activity has a RelativeLayout and contains two fragments which have LinearLayout defined in their own separate layout xml files. Do the LinearLayouts affect the way in which the RelativeLayout would normally display and vice versa?
Fragments are basically similar to other view like RelativeLayout or LinearLayout in some ways. For Example they can also have width and height; Fragments can expand on the basis of size of its children. Rest is up on you, how you design layouts (fragments). Fragment is also similar to Activity in a sense that it has its own xml layout and corresponding java class. Primarily, we use fragments in two ways:
i) One or more fragments capturing separate parts (space) of activity at a time.
ii) A particular fragment in activity which is replaced (add,remove,replace) by many other fragments programmatically
You can use fragments statically in the layout files of your activities and dynamically by adding them in containers which you also define in the layout files of your activities.
The fragment view, will be inflated and be displayed in its container. It all depends on how you define your container. If you make it so it match the width of its parent, the layout of the fragment can have a width as much as the parent of the container. It is like putting views into that container.
I've implemented a layout like this:
whit this configuration:
Fragment A: weight 1
Fragment B: weight 3
Now I want that a third fragment (Fragment C) is added in my layout, as shown in the below image:
I would that the width of screen is divided in this way:
Fragment A: weight 1
Fragment B: weight 2
Fragment C: weight 1
So that the Fragment B loses a portion of his width, while the width of Fragment A remains the same.
I want also that this operation is made with an animation. While the fragment B is appearing the fragment C loses portion of his width.
How can I achieve this?
have you tried having a look at the Android-PanesLibrary? It seems like it might be the thing you are looking for:
the menu and all other fragments appear in dynamically added panes of varying sizes.
there is also this video from his YouTube channel showing it in action.
You're looking for layout animations. Check the guide in the Android developer's training guides: http://developer.android.com/training/animation/layout.html
What you need to do is set android:animateLayoutChanges="true" for the layout (xml or in code). In your case for the ViewGroup that has your fragments (you don't show any code, so I can't give you more details). For more elaborate animations some customization might be necessary.
They also have the AndroidDevelopers YouTube channel where they go a bit deeper. This video will help you: https://www.youtube.com/watch?v=55wLsaWpQ4g
I wrote a FragmentActivity app with the use of the v4 support library, consisting of a fragment with a layout that contains a listview (list fragment), and a reusable fragment that changes its layout based on the list item selected (detail fragment).
In the layout for large screens, I have a fragment tag for the list fragment and a scrollview as a fragment container for the detail fragment, to allow fragments whose layouts overflow out of the screen.
Originally, for small screens, I used a basic ScrollView as the fragment container. But, since the listview in the list fragment is a scrollable fragment and there cannot be scrollable views in a ScrollView, it couldn't be scrolled; though the other fragments could be scrolled.
So, I changed the ScrollView to a FrameLayout instead, and while fragments with scrollable views can scroll, the fragments that overflowed the screen could not be scrolled.
How would I go about this problem, with the intention of enabling both fragments with scrollable views and overflowing fragments to scroll in a one-panel fragment view?
Thanks in advance
EDIT: I might be able to use ScrollView in the dynamic layouts used by the detail fragment as I see fit, using it where there are no scrollable views, but are there any better solutions?
Ok, I guess this does require the ScrollView to be used only in layouts in which there are no scrollable views.
I stopped using ScrollView as the root element in the fragment activity layout, and I manually used ScrollViews where applicable, and it's working now.
A better way is still welcome and appreciated.