2014-09-02 65 views
2

我需要检查View子类是否有其android:layout_height财产wrap_content或固定值从ListViewAdapter,我怎么能做到这一点编程?检查属性WRAP_CONTENT或固定高度(通过编程)

PS:这是为了做这样的事情:

// Pseudo code 
If attribute = wrap_content Then 
    calculateViewHeight(); 
Else 
    // If it was fixed, do nothing 
End if 

而且没了,我不能OverrideonMeasure()

回答

3

试试这个:

ViewGroup.LayoutParams lp = view.getLayoutParams(); 
if(lp.height == ViewGroup.LayoutParams.WRAP_CONTENT) { 
    //do something 
} else { 
    //fixed height. 
} 
+0

lp.height ==修复了ViewGroup.LayoutParams.WRAP_CONTENT – worked 2016-03-09 21:28:38

+1

。谢谢指出。 – suitianshi 2016-03-10 01:47:11