3Answers
  • 12
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

name Punditsdkoslkdosdkoskdo

does minHeight do anything?

In the attached image, I want the column of buttons to match the height of the image, but I also want there to be a minimum height for the column of buttons.

It correctly matches the height of the image, but does not respect the minHeight, and will smoosh the buttons down.

I am setting these properties for the column of buttons:

<LinearLayout
   ...
   android:layout_alignTop="@+id/image"
   android:layout_alignBottom="@+id/image"
   android:minHeight="150dp"
   >

enter image description here

I don't know all your exact requirements, but it seems you can solve this with another layer pretty much like in your diagram. Set the minHeight on an outer layout and then just fill_parent/match_parent on the inside. Maybe something like:

<LinearLayout
    android:orientation="horizontal"
    android:layout_height="wrap_content"
    android:layout_width="wrap_content"
    android:minHeight="150dp">
    <LinearLayout
        android:orientation="vertical"
        android:layout_height="fill_parent"
        android:layout_width="wrap_content">
    </LinearLayout>
    <ImageView />
</LinearLayout>
  • 56
Reply Report
    • But remember: if you use to many layouts your app might become sluggish at startup. It seems that layouts need a lot of memory at startup which might trigger garbage collection slowing down your app until the memory needed for startup has been freed again. And yes, I have that problem and currently I try to switch to RelativLayout instead.

Tricky question because it calls TextView.setMinHeight — but then you are not using a TextView.

So generally android:minHeight does indeed do something but not in your particular case.

  • 7
Reply Report
      • 2
    • @David Liu That the attribute is valid in the XML doesn't mean that it is stored in the view. And even when the attribute is stored in the view it doesn't mean that is is actually used by the active layout manager. And to make it even more fun: there is a TextView.setMinHeight and a View.setMinimumHeight
      • 2
    • The point is that bringing up TextView.setMinHeight is completely irrelevant, because the question doesn't ask about text views. As for the validity of the XML, it's clearly used and stored in the base View class, as seen here: android.googlesource.com/platform/frameworks/base/+/refs/heads/… line 970. Whether or not it is actually used by the active layout manager is irrelevant to my point (though as seen in the accepted answer, that minHeight attribute was relevant to the actual answer, as LinearLayout does take into account View.minHeight).
    • This was a good answer to the original question asked. It probably doesn't help the user achieve their end goal, but I found it interesting nonetheless.

Although my other answer is still valid, nowadays we have the benefit of ConstraintLayout. I'm sure the original poster has long since gotten past this problem, but for future users' sake: you can achieve the same result without the extra layer of ViewGroups. Something like this:

<android.support.constraint.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="wrap_content"
    android:minHeight="150dp">

    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="0dp"
        android:text="Button1"
        app:layout_constraintBottom_toTopOf="@+id/button2"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <Button
        android:id="@+id/button2"
        android:layout_width="wrap_content"
        android:layout_height="0dp"
        android:text="Button2"
        app:layout_constraintBottom_toTopOf="@+id/button3"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/button1" />

    <Button
        android:id="@+id/button3"
        android:layout_width="wrap_content"
        android:layout_height="0dp"
        android:text="Button3"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/button2" />

    <android.support.constraint.Barrier
        android:id="@+id/barrier"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:barrierDirection="end"
        app:constraint_referenced_ids="button1,button2,button3" />

    <ImageView
        android:id="@+id/image"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="@id/barrier"
        app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>

Possibly you may need something like:

    app:layout_constrainedWidth="true"

for the ImageView to handle larger images, but I haven't tested it.

  • 1
Reply Report