eugene
eugene

Reputation: 41665

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.

Upvotes: 5

Views: 4563

Answers (1)

iagreen
iagreen

Reputation: 31996

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.

Upvotes: 2

Related Questions