Example usage for android.widget ImageView getLayoutParams

List of usage examples for android.widget ImageView getLayoutParams

Introduction

In this page you can find the example usage for android.widget ImageView getLayoutParams.

Prototype

@ViewDebug.ExportedProperty(deepExport = true, prefix = "layout_")
public ViewGroup.LayoutParams getLayoutParams() 

Source Link

Document

Get the LayoutParams associated with this view.

Usage

From source file:Main.java

static public void setImageViewSize(ImageView imageView) {
    ViewGroup.LayoutParams params = imageView.getLayoutParams();
    params.height = 250;/*from w  ww  .  j a va2  s .c  om*/
    imageView.setLayoutParams(params);
    imageView.requestLayout();
}

From source file:Main.java

static public void setImageViewSizeMax(ImageView imageView, int width, int height) {
    ViewGroup.LayoutParams params = imageView.getLayoutParams();
    params.height = height;//  www.  j av a 2s  .  c  o m
    params.width = width;
    imageView.setLayoutParams(params);
    imageView.requestLayout();
}

From source file:Main.java

public static Point calcDecodeSizeHint(ImageView imageView) {
    Point p = new Point();
    LayoutParams params = imageView.getLayoutParams();
    p.x = (params != null) ? params.width : imageView.getWidth();
    p.y = (params != null) ? params.height : imageView.getHeight();
    return p;/*  ww  w .  j  a  va 2  s .c o m*/
}

From source file:Main.java

/**
 * Resize ImageView/*  w w w .  j a v a 2s  .c  o m*/
 * @param iv
 */
public static void resizeImageView(ImageView iv, int w, int h) {
    if (iv != null && w > 0 && h > 0) {
        iv.requestLayout();
        iv.getLayoutParams().width = w;
        iv.getLayoutParams().height = h;
    }
}

From source file:Main.java

/**
 * {@inheritDoc}//from w  ww.j  a  v  a  2  s  .  c  o m
 * <p/>
 * Width is defined by target {@link ImageView view} parameters,
 * configuration parameters or device display dimensions.<br />
 * Size computing algorithm:<br />
 * 1) Get the actual drawn <b>getWidth()</b> of the View. If view haven't
 * drawn yet then go to step #2.<br />
 * 2) Get <b>layout_width</b>. If it hasn't exact value then go to step #3.<br />
 * 3) Get <b>maxWidth</b>.
 */
public static int getImageViewWidth(ImageView imageView) {
    if (imageView != null) {
        final ViewGroup.LayoutParams params = imageView.getLayoutParams();
        int width = 0;
        if (params != null && params.width != ViewGroup.LayoutParams.WRAP_CONTENT) {
            width = imageView.getWidth(); // Get actual image width
        }
        if (width <= 0 && params != null) {
            width = params.width; // Get layout width parameter
        }
        if (width <= 0) {
            width = getImageViewFieldValue(imageView, "mMaxWidth");
        }
        return width;
    }
    return DEFAULT_WIDTH;
}

From source file:Main.java

/**
 * {@inheritDoc}//from w w  w. j av  a  2 s . co m
 * <p/>
 * Height is defined by target {@link ImageView view} parameters,
 * configuration parameters or device display dimensions.<br />
 * Size computing algorithm:<br />
 * 1) Get the actual drawn <b>getHeight()</b> of the View. If view haven't
 * drawn yet then go to step #2.<br />
 * 2) Get <b>layout_height</b>. If it hasn't exact value then go to step #3.
 * <br />
 * 3) Get <b>maxHeight</b>.
 */
public static int getImageViewHeight(ImageView imageView) {
    if (imageView != null) {
        final ViewGroup.LayoutParams params = imageView.getLayoutParams();
        int height = 0;
        if (params != null && params.height != ViewGroup.LayoutParams.WRAP_CONTENT) {
            height = imageView.getHeight(); // Get actual image height
        }
        if (height <= 0 && params != null) {
            // Get layout height parameter
            height = params.height;
        }
        if (height <= 0) {
            height = getImageViewFieldValue(imageView, "mMaxHeight");
        }
        return height;
    }
    return DEFAULT_HEIGHT;
}

From source file:com.todoroo.astrid.notes.CommentsController.java

private static void setupImagePopupForCommentView(View view, ImageView commentPictureView,
        final Uri updateBitmap, final Activity activity) {
    if (updateBitmap != null) {
        commentPictureView.setVisibility(View.VISIBLE);
        String path = getPathFromUri(activity, updateBitmap);
        commentPictureView.setImageBitmap(sampleBitmap(path, commentPictureView.getLayoutParams().width,
                commentPictureView.getLayoutParams().height));

        view.setOnClickListener(v -> {
            File file = new File(updateBitmap.getPath());
            Uri uri = FileProvider.getUriForFile(activity, Constants.FILE_PROVIDER_AUTHORITY,
                    file.getAbsoluteFile());
            Intent intent = new Intent(Intent.ACTION_VIEW);
            intent.setDataAndType(uri, "image/*");
            FileHelper.grantReadPermissions(activity, intent, uri);
            activity.startActivity(intent);
        });//from w w w .j a  v  a2 s. c  om
    } else {
        commentPictureView.setVisibility(View.GONE);
    }
}

From source file:com.yanzhenjie.album.task.LocalImageLoader.java

/**
 * According to the ImageView obtains appropriate width and height of compression.
 *
 * @param imageView {@link ImageView}.//from  www.  j a v a 2s.  co  m
 * @param viewSizes ViewSize.
 */
public static void measureSize(ImageView imageView, int[] viewSizes) {
    final DisplayMetrics displayMetrics = imageView.getContext().getResources().getDisplayMetrics();
    final LayoutParams params = imageView.getLayoutParams();
    if (params == null) {
        viewSizes[0] = displayMetrics.widthPixels;
        viewSizes[1] = displayMetrics.heightPixels;
    } else {
        viewSizes[0] = params.width == LayoutParams.WRAP_CONTENT ? 0 : imageView.getMeasuredWidth(); // Get actual image width
        viewSizes[1] = params.height == LayoutParams.WRAP_CONTENT ? 0 : imageView.getMeasuredWidth(); // Get actual image
        // height

        if (viewSizes[0] <= 0)
            viewSizes[0] = displayMetrics.widthPixels; // Get layout width parameter
        if (viewSizes[1] <= 0)
            viewSizes[1] = displayMetrics.heightPixels; // Get layout height parameter
    }
}

From source file:Main.java

@SuppressWarnings("deprecation")
@TargetApi(Build.VERSION_CODES.HONEYCOMB_MR2)
public static void resizeImageView(Context ctx, ImageView imgView) {
    WindowManager wm = (WindowManager) ctx.getSystemService(Context.WINDOW_SERVICE);
    Display display = wm.getDefaultDisplay();
    int width;/*  ww w. j  ava2s  .  co  m*/
    // int height;
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB_MR2) {
        width = display.getWidth(); // deprecated
        // height = display.getHeight(); // deprecated
    } else {
        Point size = new Point();
        display.getSize(size);
        width = size.x;
        // height = size.y;
    }

    imgView.setMinimumHeight(width);
    imgView.setMinimumWidth(width);
    imgView.getLayoutParams().height = width;
    imgView.getLayoutParams().width = width;
}

From source file:com.todoroo.astrid.notes.EditNoteActivity.java

private static void setupImagePopupForCommentView(View view, ImageView commentPictureView,
        final Uri updateBitmap, final Fragment fragment) {
    if (updateBitmap != null) { //$NON-NLS-1$
        commentPictureView.setVisibility(View.VISIBLE);
        String path = getPathFromUri(fragment.getActivity(), updateBitmap);
        commentPictureView.setImageBitmap(sampleBitmap(path, commentPictureView.getLayoutParams().width,
                commentPictureView.getLayoutParams().height));

        view.setOnClickListener(new OnClickListener() {
            @Override//from   w  ww .j  a v a  2  s. c o  m
            public void onClick(View v) {
                fragment.startActivity(new Intent(Intent.ACTION_VIEW) {
                    {
                        setDataAndType(updateBitmap, "image/*");
                    }
                });
            }
        });
    } else {
        commentPictureView.setVisibility(View.GONE);
    }
}