Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

getting a view WIDTH with match_parent property?

I have an imageView with layout_width="match_parent".

On my adapter's getView(), I'd like to get the actual width of this imageView but don't know how.

I tried using imageView.getWidth(), but this returns 0.

like image 547
eugene Avatar asked Nov 03 '22 08:11

eugene


1 Answers

The view is not attached to its parent group in getView(), so it hasn't been measured, hence the zero width. The only way I can think of is to do a parent.getWidth() which returns the width of the ViewGroup. This will only work when your view is not going to be placed next to another view in parent. This is usually the case for ListView, so may work for your case.

like image 181
iagreen Avatar answered Nov 15 '22 00:11

iagreen