• 15
name

A PHP Error was encountered

Severity: Notice

Message: Undefined index: userid

Filename: views/question.php

Line Number: 191

Backtrace:

File: /home/prodcxja/public_html/questions/application/views/question.php
Line: 191
Function: _error_handler

File: /home/prodcxja/public_html/questions/application/controllers/Questions.php
Line: 433
Function: view

File: /home/prodcxja/public_html/questions/index.php
Line: 315
Function: require_once

I have a layout composed of a ScrollView with a ConstraintLayout as a container. This container has some views and I want one of those views to have a maximum height, so I used layout_constrainedHeight_max, but then the view just disapear when lauching the app...

Here is my xml sample :

<ScrollView
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fillViewport="true">

    <android.support.constraint.ConstraintLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:isScrollContainer="true">

        <ImageView
            android:id="@+id/imageView1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginStart="8dp"
            android:layout_marginTop="8dp"
            android:layout_marginEnd="8dp"
            app:layout_constrainedHeight="true"
            app:layout_constraintHeight_max="20dp"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent"
            app:srcCompat="@mipmap/ic_launcher" />

        <ImageView
            android:id="@+id/imageView2"
            android:layout_width="0dp"
            android:layout_height="1500dp"
            android:layout_margin="8dp"
            android:background="@android:color/darker_gray"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/imageView1"/>

    </android.support.constraint.ConstraintLayout>

</ScrollView>

I simplified the xml to just reproduce the bug with minimum components. I tried many things but imageView1 just keep disappearing and I don't understand why. fillViewport or isScrollContainer changed nothing and I am using version 1.1.3 of constraint-layout. ImageView1 will appear if the constraintlayout is not in a ScrollView or if I don't use layout_constraintHeight_max (android:maxHeight doesn't work) but the combination of both just doesn't work. So what am I missing ?

    • Hi @Kelly which one is ImageView1 as it seems the two of them are being called this way? Is the bottom image or the top one that is disappearing please? Thanks.
    • Can you maybe as a test add some width and height to the first image instead of using wrap content? Also is your second image supposed to be that big, 1500dp or it should be just 150dp? It seems too big and that may be why the other image is not being shown.
    • Hi @FrancislainyCampos sorry for the confusion I edited the post. I was talking about the top image, the one with app:layout_constraintHeight_max, the second is just here to have something to scroll (in fact it could be anytihng or several views it does not have influence on the first one). I tried a fixed height instead of wrap content like you suggested. ImageView1 does appear but at the height I fixed and app:layout_constraintHeight_max becomes useless which is not what I want sadly. Think of ImageView1 as an image which you don't know the size in advance but don't want to appear too big.

It turns out that for layout_constraintWidth_max and layout_constraintHeight_max to work all constraints (left, right, top, bottom) needs to be set. It is not applicable to imageView1 as a view at the top with variable height and other views relating to it.

I assume you want to make your imageView1 have a maximum height of 20dp. To achieve that try this code:

<ImageView
    android:id="@+id/imageView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginStart="8dp"
    android:layout_marginTop="8dp"
    android:layout_marginEnd="8dp"
    android:adjustViewBounds="true"
    android:maxHeight="20dp"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent"
    app:srcCompat="@mipmap/ic_launcher" />

Here changes are:

  1. adding android:maxHeight="20dp" and android:adjustViewBounds="true"
  2. removing app:layout_constrainedHeight="true" and app:layout_constraintHeight_max="20dp"

I would also advice you to set layout_height attribute of ConstraintLayout to wrap_content as ScrollView is assumed to contain a child that is bigger than itself.

  • 1
Reply Report