• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

How to fix ConstraintLayout inside ScrollView is not scolling?

1Demo

Lurker
Aug 26, 2019
2
0
Hello,

My App contains many buttons, which are shown under each other, two per row. I generate the buttons dynamically via Java, which are them shown in the ConstraintLayout.

Code:
<?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">


        <androidx.constraintlayout.widget.ConstraintLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/rootLayout"
            >

            </androidx.constraintlayout.widget.ConstraintLayout>

    </ScrollView>

I have tried several layouts beside the ConstraintLayout, the TableView scrolling worked, however the button are not in the correct place then.

This is how the buttons are generated:

Java:
Button b = new Button(this);
            b.setText(myClass.getTitle());
            b.setTextColor(0xFFFFFFFF);
            b.setX(buttonX);
            b.setY(buttonY);
            b.setWidth(buttonWidth);
            b.setHeight(buttonHeight);
            conLayout.addView(b);
 

BEST TECH IN 2023

We've been tracking upcoming products and ranking the best tech since 2007. Thanks for trusting our opinion: we get rewarded through affiliate links that earn us a commission and we invite you to learn more about us.

Smartphones