So recently, with Android Studio 2.2 there's a new ConstraintLayout that makes designing a lot easier, but unlike RelativeLayout
and Linearlayout
, I can't use a ScrollView
to surround ConstraintLayot
. Is this possible? If so, how?
i.e.
<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"
tools:layout_editor_absoluteX="0dp"
tools:layout_editor_absoluteY="0dp">
<android.support.constraint.ConstraintLayout
android:id="@+id/constraintLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:layout_editor_absoluteX="0dp"
tools:layout_editor_absoluteY="0dp">
<!-- Have whatever children you want inside -->
</android.support.constraint.ConstraintLayout>
</ScrollView>
Try adding
android:fillViewport="true"
to the ScrollView.Found the solution here: LinearLayout not expanding inside a ScrollView
Since the actual
ScrollView
is encapsulated in aCoordinatorLayout
with aToolbar
...... I had to define
android:layout_marginTop="?attr/actionBarSize"
to make the scrolling working:Above also works with
NestedScrollView
instead ofScrollView
. Definingandroid:fillViewport="true"
is not needed for me.Set
ScrollView
layout_height
as awrap_content
then it will work fine. Below are example which may help someone. I have usedcompile 'com.android.support.constraint:constraint-layout:1.0.2'
for constraint layout.I have reported the bug to the Google team.
You can view it here.
New android studio after 2.2 ConstraintLayout now works properly inside ScrollView.
Like this below example:
I hope it'll help you ..!
I've spent 2 days attempting to convert layouts to
ConstraintLayout
in the so-called "stable" release Android Studio 2.2 and I've not gotScrollView
to work in the designer. I'm not going to start down the route of adding constraints in XML forViews
that are further down the scroll. After all this is supposed to be a visual design tool.And the number of rendering errors, stack overflows and theme issues I've had has led me to conclude that the whole
ConstraintLayout
implementation is still riddled with bugs. Unless you are developing simple layouts then I'd leave it well alone until it's had a few more iterations at least.That's 2 days I'm not going to get back.