Rowan John Stringer
Rowan John Stringer

Reputation: 171

What is the difference between setMinHeight and setMinimumHeight on a View in Android?

I'm have a custom View containing 8 TextViews that I am using as a row in a table. I need to set the minimum height of these children once the data has been inserted as I would like the height of all 8 TextViews to expand to the height of the tallest one.

I am currently doing this in code as follows:

for(int i = 0; i < m_textViews.length; i++)
{
    m_textViews[i].setMinHeight(heightPx);
    m_textViews[i].setHeight(heightPx);
}

I am trying to improve the code performance, leading me to wonder actually what the difference was between setMinHeight() and setMinimumHeight()?

Thanks in advance

Upvotes: 7

Views: 3976

Answers (2)

Antwan Kakki
Antwan Kakki

Reputation: 250

I recommend using setMinHeight because it is written for TextViews specifically and it updates the mMinMode to hold PIXELS value

Here is SetMinHeight from the TextView.java sourceCode

/**
* Makes the TextView at least this many pixels tall.
*
* Setting this value overrides any other (minimum) number of lines setting.
*
* @attr ref android.R.styleable#TextView_minHeight
*/
@android.view.RemotableViewMethod
public void setMinHeight(int minHeight) {
    mMinimum = minHeight;
    mMinMode = PIXELS;
    requestLayout();
    invalidate();
}

and Here is SetMinimumHeight from the View.java SourceCode

/**
* Sets the minimum height of the view. It is not guaranteed the view will
* be able to achieve this minimum height (for example, if its parent layout
* constrains it with less available height).
*
* @param minHeight The minimum height the view will try to be.
*
* @see #getMinimumHeight()
*
* @attr ref android.R.styleable#View_minHeight
*/
public void setMinimumHeight(int minHeight) {
    mMinHeight = minHeight 
    requestLayout();
}

References:

TextView.java:

http://androidxref.com/5.1.0_r1/xref/frameworks/base/core/java/android/widget/TextView.java

View.java:

http://androidxref.com/5.1.0_r1/xref/frameworks/base/core/java/android/view/View.java

Upvotes: 5

daniel.keresztes
daniel.keresztes

Reputation: 885

setMinHeight(int minHeight)

Makes the TextView at least this many pixels tall. Setting this value overrides any other (minimum) number of lines setting.

setMinimumHeight(int minHeight)

Sets the minimum height of the view. It is not guaranteed the view will be able to achieve this minimum height (for example, if its parent layout constrains it with less available height).

Upvotes: 3

Related Questions