Scrollview inside of a scrollview - android

BEFORE YOU SAY "Google says not to do this" PLEASE READ ALL OF MY QUESTION!!
The layout:
ScrollView -> RelativeLayout -> ScrollView -> RelativeLayout
The first ScrollView is necessary because form entries pull up the soft keyboard on some phones which hides the rest of the content. Having a ScrollView as the outer most container allows a user to scroll with the soft keyboard present.
The second ScrollView lower on the hierarchy is a ListView which is still scrollable.
I completely understand why devs are discouraged to have a ScrollView within another ScrollView. I need to figure out a way to get the two to work together. I tried disabling the outermost ScrollView when the inner most ScrollView get's a touch, but that didn't help.
Is there a way to get around this to where both will work (not at the same time of course)? I wouldn't even mind disabling the outermost ScrollView until the content page is changed again. There has to be a way..

Step #1: Remove the ScrollView.
Step #2: Make the first RelativeLayout be a header in your ListView via addHeaderView().
Step #3: Make the second RelativeLayout be a footer in your ListView via addFooterView().
The net effect is that the whole thing will be scrollable, without nested scrollable items.

It will only work when you set the android:layout_height to a fixed value for your second ScrollView. The best way is to set a size depending on device, for that it would be better to create layout for each supported screen size ( value on dp like 150 dp).
you shoud create separate layout: layout-small, layout-normal, layout-large ....
see this link for optimization of the fixed size: http://developer.android.com/guide/practices/screens_support.html

The answer is to programmatically intercept the touch events form the outer most scrollview. I am using a class that I found in another SOF about Disabling a ScrollView Programattically.

Related

Multiple non-scrollable lists in a ScrollView in Android

I am trying to put multiple lists that don't need to be scrollable inside a ScrollView. In other words, I have a TextView as a header for a category, with a list under it. Then another TextView as another header, with another list under that. And so on. This is in a vertical LinearLayout.
I want to be able to scroll through this layout as it gets off the screen when it has too much info, but I want all the contents of the lists to be displayed.
I've tried putting the headers (the TextViews) and the lists inside a vertical LinearLayout, and that LinearLayout inside a ScrollView. The problem with that approach is - all the lists have a max vertical dimension of exactly one element (if I set them to "wrap content"), despite the lists having multiple elements. Believe it or not, the lists do scroll (and they're inside of a ScrollView, more exactly, inside of a ScrollView -> LinearLayout).
If I remove the ScrollView, then the lists do indeed appear with all their elements, but I can't scroll the view if it goes off the screen.
So, if I use a ScrollView, I only get one element per each list. If I don't use it, I get all the elements of the lists correctly, but it doesn't scroll.
Any ideas of solving this? Thanks!
Nevermind, eventually found the answer here and it works perfectly:
https://stackoverflow.com/a/27818748/5627584
This ^^^ is a very underrated answer as I have hardly found it, but it's very, very useful when trying to include lists inside of superior layout node that has to be scrollable (inside of a ScrollView -> LinearLayout that contains other interface elements).

Scrollability of Android Linear Layout

According to this
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.
I have a Linear Layout (vertical) that consist of a stack of TextView, EditText and one button. Reading the documentation above, I would expect that my layout will scroll by default when there is not enough space to display (e.g. when soft keyboard is on). But apparently it doesn't scroll until I wrap my Linear Layout with ScrollView.
Do I understand the documentation incorrectly? Please help me to understand this. Thanks.
Do I understand the documentation incorrectly?
It is a bug in the documentation. LinearLayout does not scroll on its own.

How to place UI elements to the position we want in Android?

I have some buttons, textboxes etc. in my android application, but when i drag them with my mouse in the xml file, their place doesn't change, or changes but they are not placed where i exactly wanted. How can i adjust their positions in the screen?
Thanks
Unfortunatly there is no such thing as absolute positionning in android ( RIP AbsoluteLayout deprecated since years.)
instead you have to position views according to their parents and according to other views in the same parent.
first you have to define wich parent you need ( if you want some viens in a single line go for a LinearLayout. a more custom layout: use a RelativeLayout ...)
then you can drag and drop views inside, but they will always snap a position relative to their parent and/or relative to the other views.
you can of course play with margins.
A list of layout type with some advanced techniques can be found on this page
Hope that helps.
You RelativeLayout as a group layout for your layout so positioning can somewhat easy using mouse.
Best is to arrange them from the xml code. Just Learn about using the Relative layout, LinearLayout and TableLayout
Learn how the XML works. For a LinearLayout, the items come in the order listed. For a RelativeLayout, the items are related by the values of their layout_XXX properties. Then you don't have to worry about the WYSIWYG tool not working.
FYI, the tool bundled with eclipse is extremely buggy. Don't count on whats on there being what's on your phone for anything non-trivial.
Like the others wrote it is easier to edit layout using xml editor. You can read more here http://developer.android.com/guide/topics/ui/declaring-layout.html.

How to scroll only the widgets(Content) but not the background in android

I defined ScrollView and I put inside some buttons. I have two problems:
If I have a little bit buttons then the background is too small
and does not cover whole screen.
I want to just move buttons but not the the background when I
scroll.
Thank you
Put the scrollview inside a linear layout or a framelayout and add the background to the outer layouts. So when only the items in your scroll view will move.
Also try adding background directly to the scrollview and not to its child elements, that might work without needing to add a extra out layout like I mentioned above.
For your first question, what is the scrollview's layout_width and layout_height values? I'm guessing it's wrap_content. Try changing it to match_parent or fill_parent.
For your second question, blessenm's reply works for me.

ExpandableListView affecting the size of Scrollview when collapsing and expanding

Let me try to explain what I want to achieve. Currently, I have a ScrollView as the main view for my layout and a linearLayout within that to place all of my content into.
In my LinearLayout, I have a bunch of textviews and a gallery, which extends out of the screen, so the user can scroll to see everything. It works.
Now, I want to add an expandableListView to the bottom of all that content, which is still in the linearLayout. The problem is when you expand the list view groups it doesn't affect the ScrollView. I had envisaged that when you expand a group it would make the linearLayout bigger, which in turn makes the scrollview bigger.
Is what I'm thinking achievable?
EDIT:
Ok I think the situation is that listViews are normally placed in a layout by themselves and have scrollviews already enabled. You just set it to fill_parent and it works fine. However, in my case, I'll need the expandableListView to display all content without scrolling, because my ScrollView will deal with that. I don't even think it possible?
It's difficult to answert without seeing your layout xml, but I think that if you set the android:layout_height of the linear layout and expandableListView to wrap_content, the first scrollView must scroll the whole view.
have you tried putting your expandable list into another linear layout and than put it in the scroll views default linear layout?

Categories

Resources