Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 835
Rowan John Stringer Avatar asked Jun 24 '15 09:06

Rowan John Stringer


2 Answers

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

like image 154
Antwan Kakki Avatar answered Nov 15 '22 00:11

Antwan Kakki


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).

like image 37
daniel.keresztes Avatar answered Nov 14 '22 22:11

daniel.keresztes