[英]What is the difference between setMinHeight and setMinimumHeight on a View in Android?
我有一個包含8個TextView
的自定義View
,我正在將其用作表中的一行。 插入數據后,我需要設置這些子項的最小高度,因為我希望將所有8個TextView
的高度擴展到最高的高度。
我目前正在執行以下代碼:
for(int i = 0; i < m_textViews.length; i++)
{
m_textViews[i].setMinHeight(heightPx);
m_textViews[i].setHeight(heightPx);
}
我正在嘗試提高代碼性能,使我想知道實際上setMinHeight()
和setMinimumHeight()
之間有什么區別?
提前致謝
我建議使用setMinHeight,因為它是專門為TextViews編寫的,並且它更新mMinMode來保存PIXELS值
下面是從TextView.java源代碼SetMinHeight
/**
* 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();
}
這里是從View.java源碼SetMinimumHeight
/**
* 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();
}
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
setMinHeight(int minHeight)
使TextView至少高出這么多像素。 設置此值將覆蓋任何其他(最小)行數設置。
setMinimumHeight(int minHeight)
設置視圖的最小高度。 無法保證視圖將能夠達到此最小高度(例如,如果其父級布局以較小的可用高度限制它)。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.