I am trying to get the size of the image displayed on my screen, not the original size of the image.
I already did some research on it and I found the same question on the unresolved post two years old, so I was thinking maybe now there is a new way to do it.
I tried this 3 solutions :
//Get the same result for all my images (whereas images have difference sizes)
imageView.getWidth() + imageView.getHeight()
//Get the original size of the images
imageView.getDrawable().getIntrinsicWidth() + imageView.getDrawable().getIntrinsicHeight()
bitMap.getWidth() + bitMap.getHeight()
My xml :
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="1dip" >
<ImageView
android:id="@+id/image"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center"
android:adjustViewBounds="true"
android:contentDescription="@string/descr_image"
android:layout_alignParentBottom="true" />
<ProgressBar
android:id="@+id/loading"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:visibility="gone" />
<WebView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/webView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
/>
</RelativeLayout>
Update 1
ViewTreeObserver viewTreeObserver = imageView.getViewTreeObserver();
if (viewTreeObserver.isAlive()) {
viewTreeObserver.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
@SuppressWarnings("deprecation")
public void onGlobalLayout() {
imageView.getViewTreeObserver().removeGlobalOnLayoutListener(this)
System.out.println("TEST :" + imageView.getWidth() + " " + imageView.getHeight());
}
});
}