Matan Fattal
Matan Fattal

Reputation: 21

android TouchImageView height don't change

I'm using TouchImageView (https://github.com/MikeOrtiz/TouchImageView) to show bitmap in full screen. When I put the normal bitmap:

touchImageView.setImageBitmap(bm);

If a user double tap or 2 finger-pinch-zoom the picture zooms but the TouchImageView width/height stays the same.

When i put bitmap that is bigger then the screens width/height everything works as expected :

Bitmap new_bm = Bitmap.createScaledBitmap(bm, 
            more_px_then_screen_width, more_px_then_screen_height, false);
touchImageView.setImageBitmap(bm);

Here is the xml:

    <TouchImageView 
    android:id="@+id/picture_full_screen"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerInParent="true" />

Please Help !

Upvotes: 1

Views: 656

Answers (1)

Matan Fattal
Matan Fattal

Reputation: 21

After investigating i found this function:

/**
 * Set view dimensions based on layout params
 * 
 * @param mode 
 * @param size
 * @param drawableWidth
 * @return
 */
private int setViewSize(int mode, int size, int drawableWidth) {
    int viewSize;
    switch (mode) {
    case MeasureSpec.EXACTLY:
        viewSize = size;
        break;

    case MeasureSpec.AT_MOST:
        viewSize = Math.min(drawableWidth, size);
        break;

    case MeasureSpec.UNSPECIFIED:
        viewSize = drawableWidth;
        break;

    default:
        viewSize = size;
        break;
    }
    return viewSize;
}

later on it would be user in onMeasure to calculate viewWidth, viewHeight that are used in

setMeasuredDimension(viewWidth, viewHeight);

Changing setViewSize to this got me the desired effect:

/**
 * Set view dimensions based on layout params
 * 
 * @param mode 
 * @param size
 * @param drawableSize
 * @return
 */
private int setViewSize(int mode, int size, int drawableSize) {
    int viewSize;
    switch (mode) {
    case MeasureSpec.EXACTLY:
        viewSize = (int) (size*Math.max(normalizedScale, 1.0));
        break;

    case MeasureSpec.AT_MOST:
        viewSize = (int) (size*Math.max(normalizedScale, 1.0));
        break;

    case MeasureSpec.UNSPECIFIED:
        viewSize = drawableSize;
        break;

    default:
        viewSize = (int) (size*Math.max(normalizedScale, 1.0));
        break;
    }
    return viewSize;
}

I changed the name of drawableWidth to drawableSize for code tiding because the function used to calculate the width and the height as well.

Hope someone would find this helpful.

Upvotes: 1

Related Questions