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.
Related
My Idea is adding TextViews with rounded corners background to a horizontal LinearLayout, so if next one wouldn't fit - I will add TextView to another LinearLayout below.
Is there a way to do so? I know it sound like a custom view, but I would like not to bother as much - to adjust height, make click area calculations istead of simple clickListeners
Sounds like a recyclerview using a flexbox layout https://github.com/google/flexbox-layout with flexWrap turned on.
You could also use is in a static layout as well.
With flexWrap it does all the calculations to see if the "item" can fit on a line and if not starts a new line.
Many examples on the github page.
You could keep adding text views in linear layout while checking if newly added text view is outside of linear layout horizontal boundaries, if it is you could remove it from linear layout and add it in new one but I see no reason why you would want to do that.
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.
I have made a very simple collection of ImageButtons using XML in android, with the parent layout being LinearLayout with orientation set to vertical.
I read on that LinearLayout adds the scroll automatically if the height of the content exceeds the screen.
The link is: http://developer.android.com/guide/topics/ui/declaring-layout.html
The introduction below the LinearLayout diagram says so.
But the problem is that content is not being displayed after the window's height and content is missing.
I am at my wit's end and have searched other's answered questions... I donot want to use a ListView, but if i have to, i'll do it.
Thanks
I have to create Text Views and Edit Texts dynamically and insert it inside the linear layout(horizontal) which is already declared in the XML file. Number of Text Views and Edit Texts to be inserted varies dynamically. I am creating the views dynamically and adding it to the linear layout.But the problem is that if number of views is more it moves out of the screen in spite of coming in the next line.what should I do to make the views come in next line if no space is available.
There is currently no Android layout with that behaviour.
Nevertheless, it has already been tackled in other threads (such as Android - LinearLayout Horizontal with wrapping children), which provide guidance on how to implement such a layout.
You can't do it with linearlayout, try tablelayout!
Use ScrollView and add your LinearLayout into ScrollView.
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?