1

I have a problem to include a ScrollView with a ConstraintLayout. How Can I mix the two? I would like to get a good resizing of the screen, but with the capability by scrolling the screen if the number of the buttons will increase.

I tried this, but without success. I used that ticket

enter image description here
here is the xml file:

<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
    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:id="@+id/homeContainer"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/imagealliance"
    android:backgroundTint="#80FFFFFF"
    android:backgroundTintMode="src_over"
    android:gravity="center"
    android:theme="@style/AppTheme"
    tools:context=".LoginActivity">

    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:adjustViewBounds="true"
        android:alpha="0.6"
        android:scaleType="fitXY"
        android:src="@drawable/logoalliance"
        app:layout_constraintBottom_toTopOf="@+id/txt_login"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />
    
</androidx.constraintlayout.widget.ConstraintLayout>

</ScrollView>

Here is the code for the buttons:

public class HomeFragment extends Fragment {
...
                        layout.addView(eventBtn);

                        if (i == 0)
                        {
                            test1 = eventBtn.getId();
                            Log.d("test1", String.valueOf(eventBtn.getId()));
                        }
                        if (i == countUser.length() - 1)
                        {
                            test2 = eventBtn.getId();
                            Log.d("test2", String.valueOf(eventBtn.getId()));
                        }

Here is the code for the layout:

 // Create ConstraintSet
                        ConstraintSet constraintSet = new ConstraintSet();
                        // Make sure all previous Constraints from ConstraintLayout are not lost
                        constraintSet.clone(layout2);

                        // Create Rule that states that the START of btn_contact_us1 will be positioned at the END of btn_contact_us2
                        constraintSet.connect(imageView1.getId(), ConstraintSet.START, test1, ConstraintSet.END);
                        constraintSet.applyTo(layout2);

Thanks in advance

ΩlostA
  • 2,501
  • 5
  • 27
  • 63

1 Answers1

0

Try updating your xml by following code

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 
    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:context=".MainActivityStack">

    <ScrollView
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:fillViewport="true"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent">

        <ImageView
            android:id="@+id/imageView1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:adjustViewBounds="true"
            android:alpha="0.6"
            android:scaleType="fitXY"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent" />

    </ScrollView>

</androidx.constraintlayout.widget.ConstraintLayout>
Dharman
  • 30,962
  • 25
  • 85
  • 135
Mahesh Pandit
  • 348
  • 3
  • 7
  • I tried it, but it still doesn't work. May be it is the fact that it is a fragment in a navigationcontroller ? – ΩlostA Apr 17 '21 at 18:25