I can't get the width of an ImageView in my ListAdapter's getView method...
<ImageView
android:id="@+id/photoPost"
android:layout_width="match_parent"
android:layout_height="0dp"
android:visibility="gone" />
In my ListAdapter's getView...
holder.photoPost = (ImageView) convertView.findViewById(R.id.photoPost);
int targetHeight = holder.photoPost.getWidth() * (9/16);
I'm toasting the targetHeight and it's always 0 which means the getWidth() method is returning 0. I've tried many different things. Please help!
The problem is that when you try to
getWidth, yourImageViewhave not been appeared on the screen, so it always returns 0. So there are two ways, you can get the width:First way
You need to
measureyourImageViewand then get themeasuredWidth:Second way
Add
onGlobalLayoutListenerto yourImageViewand then, you will be able to get the width: