How to make android scrollable
How to make android scrollable
How do I make a LinearLayout scrollable?
After I start the activity I am unable to scroll down to see other buttons and options in the xml defined below.
Does anyone know how to make this scrollable?
My class code is
9 Answers 9
Trending sort
Trending sort is based off of the default sorting method — by highest score — but it boosts votes that have happened recently, helping to surface more up-to-date answers.
It falls back to sorting by highest score if no posts are trending.
Switch to Trending sort
Place your layout in a ScrollView.
ScrollView takes only one layout as its child.
This property is used when your softkey in android pops up and still you want your view to scroll.
You can implement it using View.scrollTo(..) also.
you can make any layout scrollable. Just under add these lines:
and at the end add
example of a non-scrollable activity:
After making it scrollable, it becomes like this:
Place all your layouts inside a ScrollView with width and height set to fill_parent.
You cannot make a LinearLayout scrollable because it is not a scrollable container.
Only scrollable containers such as ScrollView, HorizontalScrollView, ListView, GridView, ExpandableListView can be made scrollable.
I suggest you place your LinearLayout inside a ScrollView which will by default show vertical scrollbars if there is enough content to scroll.
Note : ScrollView takes only one view as its child. So better that child view be a Linear Layout
I want to make a layout that lets me scroll down using constraint layout, but I don’t know how to go about it. Should the ScrollView be the parent of the ConstraintLayout like this?
Or the other way around? Maybe someone can point me to a good tutorial on this or give an example, I can’t seem to find one.
Also, I don’t know if this is a bug or some configuration that I don’t have set up but I’ve seen images like this one :
where there are some components outside the blueprint «blue rectangle» yet they are visible, while on my side if I place a component on the «white space» I can’t see it or move it anywhere, and it appears on the component tree.
I found a way to make the constraint layout scrollable in the design tool, using a horizontal guideline to push down the constraint layout border and extend it beyond the device, after that, you can use the guideline as the new bottom of the constraint layout to anchor the components.
17 Answers 17
Trending sort
Trending sort is based off of the default sorting method — by highest score — but it boosts votes that have happened recently, helping to surface more up-to-date answers.
It falls back to sorting by highest score if no posts are trending.
Switch to Trending sort
It seems that it is working, I don’t know what dependency you were working with but in this one
Is working, this is what I did
Scroll Bottom
There is a type of constraint which breaks the scroll function:
Just make sure you are not using this constraint on any view when wanting your ConstraintLayout to be scrollable with ScrollView :
If you remove these your scroll should work.
Explanation:
Setting the height of the child to match that of a ScrollView parent is contradictory to what the component is meant to do. What we want most of the time is for some dynamic sized content to be scrollable when it is larger than a screen/frame; matching the height with the parent ScrollView would force all the content to be displayed into a fixed frame (the height of the parent) hence invalidating any scrolling functionality.
How to make android listview scrollable?
I have two listviews, but they don’t scroll. How do I correct this?
Here is my layout.xml
10 Answers 10
Trending sort
Trending sort is based off of the default sorting method — by highest score — but it boosts votes that have happened recently, helping to surface more up-to-date answers.
It falls back to sorting by highest score if no posts are trending.
Switch to Trending sort
By default ListView is scrollable. Do not put ScrollView to the ListView
I know this question is 4-5 years old, but still, this might be useful:
Sometimes, if you have only a few elements that «exit the screen», the list might not scroll. That’s because the operating system doesn’t view it as actually exceeding the screen.
So you have to make sure it’s not a design problem at first, like the list appearing to go beyond the borders of the screen but in reality, «it doesn’t», and adjust its dimensions and margin values and see if it’s starting to «become scrollable». It did, for me.
Practically its not good to do. But if you want to do like this, just make listview’s height fixed to wrap_content.
You shouldn’t put a ListView inside a ScrollView because the ListView class implements its own scrolling and it just doesn’t receive gestures because they all are handled by the parent ScrollView
Listview so have inbuild scrolling capabilities. So you can not use listview inside scrollview. Encapsulate it in any other layout like LinearLayout or RelativeLayout.
This is my working code. you may try with this.
employee bean class:
in Activity class:
Putting ListView inside a ScrollView is never inspired. But if you want your posted XML-like behavior, there’re 3 options to me:
Replace ListView s with LinearLayout s: You may add the list-items by iterating through the item-list and add each item-view to the respective LinearLayout by inflating the view & setting the respective data (string, image etc.)
How to use ScrollView in Android?
8 Answers 8
Trending sort
Trending sort is based off of the default sorting method — by highest score — but it boosts votes that have happened recently, helping to surface more up-to-date answers.
It falls back to sorting by highest score if no posts are trending.
Switch to Trending sort
Just make the top-level layout a ScrollView:
How to use ScrollView
Making the content fill the screen
As is talked about in this post, sometimes you want the ScrollView content to fill the screen. For example, if you had some buttons at the end of a readme. You want the buttons to always be at the end of the text and at bottom of the screen, even if the text doesn’t scroll.
If the content scrolls, everything is fine. However, if the content is smaller than the size of the screen, the buttons are not at the bottom.
This can be solved with a combination of using fillViewPort on the ScrollView and using a layout weight on the content. Using fillViewPort makes the ScrollView fill the parent area. Setting the layout_weight on one of the views in the LinearLayout makes that view expand to fill any extra space.
Here is the XML
The idea for this answer came from a previous answer that is now deleted (link for 10K users). The content of this answer is an update and adaptation of this post.
Working with the ScrollView
Finding these guides helpful?
We need help from the broader community to improve these guides, add new topics and keep the topics up-to-date. See our contribution guidelines here and our topic issues list for great ways to help out.
Check these same guides through our standalone viewer for a better browsing experience and an improved search. Follow us on twitter @codepath for access to more useful Android development resources.
Clone this wiki locally
When an app has layout content that might be longer than the height of the device and that content should be vertically scrollable, then we need to use a ScrollView.
To make any content vertically scrollable, simply wrap that content in a ScrollView :
Note that a ScrollView can only contain a single child element so if you need multiple things to be scrollable, you need to wrap that content into a layout as shown above.
In certain situations, you want to position content beneath the end of the scrollable content area. For example for a «terms of service» where you can only accept once you’ve scrolled through all the content. In this case, you might need to apply the android:fillViewport property to «true». Read this post by Romain Guy for a detailed look at this use case.
Note that a TextView doesn’t require a ScrollView and if you just need a scrolling TextView simply set the scrollbars property and apply the correct MovementMethod :
and then in the activity:
Now the TextView will automatically scroll vertically.
In other cases, we want content to horizontally scroll in which case we need to use the HorizontalScrollView instead like this:
and now you have a horizontally scrolling view.
Adding a ScrollView within another ScrollView can be difficult. Most of the times it won’t end well. You will end up adding few workarounds. Instead, use the NestedScrollView as outlined here. A working sample can be found here as this is very useful when working with CoordinatorLayout
Created by CodePath with much help from the community. Contributed content licensed under cc-wiki with attribution required. You are free to remix and reuse, as long as you attribute and use a similar license.
Источники информации:
- http://stackoverflow.com/questions/43098150/android-how-to-make-a-scrollable-constraintlayout
- http://stackoverflow.com/questions/13679633/how-to-make-android-listview-scrollable
- http://stackoverflow.com/questions/6674341/how-to-use-scrollview-in-android
- http://github.com/codepath/android_guides/wiki/Working-with-the-ScrollView