0

I don't understand why my ImageViewHeight is still 0 after having call "setBitmap", I need to put a marker at a precise place of the loaded picture so I have to know the size of it :

Picasso.with(iv.getContext())
    .load(AppConstants.SERVER_URL + "/api/" + question.getImage().getUrl())
    .config(Bitmap.Config.RGB_565)
    .into(new Target() {@Override
    public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) {
        iv.setImageBitmap(bitmap);
        iv.setAdjustViewBounds(true);

        Log.i("renaud", "iv.getMeasuredHeight() : " + iv.getMeasuredHeight());
        Log.i("renaud", "iv.getMeasuredWidth() : " + iv.getMeasuredWidth());

    }

    ...

});

This log "0" for height and width.

the xml (iv correspond to "area_iv"):

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical">

    <RelativeLayout
        android:id="@+id/area_relative"
        android:layout_width="wrap_content"
        android:minWidth="300dp"
        android:minHeight="200sp"
        android:layout_height="wrap_content">

        <ImageView
            android:id="@+id/area_iv"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:scaleType="centerInside"
            />

        <ImageView
            android:id="@+id/answer_iv"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            />
    </RelativeLayout>


</LinearLayout>

------------------- Thanks to you guys I did that :

Picasso.with(iv.getContext())
    .load(AppConstants.SERVER_URL + "/api/" + question.getImage().getUrl())
    .config(Bitmap.Config.RGB_565)
    .into(new Target() {@Override
    public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) {
        iv.setImageBitmap(bitmap);
        iv.setAdjustViewBounds(true);

        iv.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {@Override
            public void onGlobalLayout() {

                Log.i("renaud", "iv.getMeasuredHeight() : " + iv.getMeasuredHeight());
                Log.i("renaud", "iv.getMeasuredWidth() : " + iv.getMeasuredWidth());
                iv.getViewTreeObserver().removeOnGlobalLayoutListener(this);
            }
        });
    }



});
Renaud Favier
  • 1,645
  • 1
  • 17
  • 33

0 Answers0