I want to make a layout that lets me scroll down using constraint layout, but I dont know how to go about it. should the scrollview be the parent of the constraintlayout like this?
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
<android.support.constraint.ConstraintLayout
android:id="@+id/Constraint"
android:layout_width="match_parent"
android:layout_height="match_parent">
</android.support.constraint.ConstraintLayout>
Or the other way around? maybe someone can point me to a good tutorial on this or give an example, I cant seem to find one.
Also I dont know if this is a bug or some configuration that I dont 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 cant see it or move it anywhere,and it appears on the component tree.
UPDATE
I found a way to make the constraint layout scrollable in the design tool, using a horiontal guideline to push down the constraint layout border and extend it beyond the device, after that you can use the guide line as the new bottom of the constraint layout to anchor the components.
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 withScrollView
: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 parentScrollView
would force all the content to be displayed into a fixed frame (the height of the parent) hence invalidating any scrolling functionality.This also happens when regular direct child components are set to
layout_height="match_parent"
.If you want the child of the
ScrollView
to match the height of the parent when there is not enough content, simply setandroid:fillViewport
to true for theScrollView
.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 Top
Scroll Bottom
There is a bug in version 2.2 that makes it impossible to scroll the ConstraintLayout. I guess it still exists. You can use LinearLayout or RelativeLayout alternatively.
Also, check out: Is it possible to put a constraint layout inside a ScrollView.
TO make a scrollable layout, the layout is correct. It will not be scrollable until there is reason to scroll(just like in any other layout). So add enough content and it will be scrollable, just like with any layout(Linear, Relative, etc). However, you cannot scroll properly in Blueprint or design-mode when designing with ConstraintLayout and ScrollView.
Meaning:
You can make a scrollable ConstraintLayout, but it will not scroll properly in the editor due to a bug/scenario that wasn't considered. But even though scrolling doesn't work in the editor, it works on devices. (I have made several scrolling COnstraintLayouts, so I have tested it)
Note
Regarding your code. The ScrollView is missing a closing tag, I don't know if it is the case in the file or if it is a copy-paste miss, but you may want to look at it.
To summarize, you basically wrap your
android.support.constraint.ConstraintLayout
view in aScrollView
within the text of the*.xml
file associated with your layout.Example activity_sign_in.xml
End Example
Note 1: that the scroll bars only appear if a wrap is needed in any way, including the keyboard popping up.
Note 2: It also wouldn't be a bad idea to make sure your contraintLayout is big enough to the reach the bottom and sides of any given screen, especially if you have a background, as this will ensure that their isn't odd whitespace. You can do this with spacers if nothing else.
Constraintlayout is the Default for a new app. I am "learning to Android" now and had a very hard time figuring out how to handle the default "sample" code to scroll when a keyboard is up. I have seen many apps where I have to close the keyboard to click "submit" button and sometimes it does not goes away. Using this [ScrollView / ContraintLayout / Fields] hierarchy it is working just fine now. This way we can have the benefits and ease of use from ConstraintLayout in a scrollable view.