1

No matter what I type in layout_height, the height of ConstraintLayout seem to be the same as phone screen size. Is there any way I could design it to automatically fit its height to total height of its content?

enter image description here

<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"
    tools:context="stfn.personaltrainer.activities.Training">

    <android.support.constraint.ConstraintLayout
        android:layout_width="match_parent"
        android:layout_height="10dp">

        <TextView
            android:id="@+id/exerciceName"
            android:layout_width="277dp"
            android:layout_height="41dp"
            android:layout_marginTop="4dp"
            android:text="Exercice name"
            android:textAlignment="center"
            android:textSize="36sp"
            app:layout_constraintHorizontal_bias="0.504"
            app:layout_constraintLeft_toLeftOf="parent"
            app:layout_constraintRight_toRightOf="parent"
            app:layout_constraintTop_toTopOf="parent" />

        <!-- TextViews, Buttons, etc. -->

        <Button
            android:id="@+id/repetitionsDone"
            android:layout_width="118dp"
            android:layout_height="wrap_content"
            android:layout_marginTop="50dp"
            android:onClick="goToNextSeries"
            android:text="@string/done"
            android:textAppearance="@style/TextAppearance.AppCompat.Button"
            app:layout_constraintLeft_toLeftOf="parent"
            app:layout_constraintRight_toRightOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/repetitionsInCurrentSeries" />

    </android.support.constraint.ConstraintLayout>

</ScrollView>
Piotrek
  • 9,838
  • 14
  • 66
  • 120
  • I think it's not good to use scrollView as a parent for ConstraintLayout, also there is unnecessary space because you are define custom height `android:layout_height="41dp"` that make scrollView expanded. –  Aug 04 '17 at 11:31
  • @Ibrahim why wouldn't be good to put a ConstraintLayout inside a ScrollView? – lelloman Aug 04 '17 at 11:32
  • Well, (it's my opinion) i used [ConstraintLayout](https://developer.android.com/training/constraint-layout/index.html) with a non screen scoll, it's perfect in this case e.g : a model for recycleView, a non scroll screen, but if i have to use scrollView, i prefer to use another layout e.g relative or linear. –  Aug 04 '17 at 11:41
  • and for your case, you may used an older version, it's a bug met with scrollView, see [this](https://stackoverflow.com/questions/37349845/android-is-it-possible-to-put-a-constraint-layout-inside-a-scrollview) –  Aug 04 '17 at 11:45
  • @Ibrahim: yes, I have defined custom height to `41dp`, but to TextView, not layout. Does custom view of TextView affect layout somehow? Maybe you meant this line: `android:layout_height="10dp"`, but as I said in question details: no matter what I type here, height of ConstraintLayout doesn't change – Piotrek Aug 04 '17 at 12:16
  • @Ibrahim: and I'm using currently the newest stable version of Android Studio. I don't think question you've linked is connected to my problem; in my case, `ConstraintLayout` works correctly in ScrollView, but leaves too much free space at the bottom – Piotrek Aug 04 '17 at 12:19
  • @Piotrek I mean (i assumed) there is many items more in the constraint with custom height and margints to top, so that add the height to the constrainLayout with scroll ability, the custom height for ConstrainLayout dosn't make any effect indeed, –  Aug 04 '17 at 12:20

1 Answers1

0

Change the height in for layout to fill the whole screen with:

    android:layout_height="match_parent"
tuxdost
  • 53
  • 11