Example usage for android.widget ImageView setLayoutParams

List of usage examples for android.widget ImageView setLayoutParams

Introduction

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

Prototype

public void setLayoutParams(ViewGroup.LayoutParams params) 

Source Link

Document

Set the layout parameters associated with this view.

Usage

From source file:Main.java

public static View getView(int width, Context mContext) {
    // Make an ImageView to show a photo
    ImageView i = new ImageView(mContext);
    i.setAdjustViewBounds(true);/* ww  w  .  j  a  v  a2  s . c o m*/
    i.setLayoutParams(new AbsListView.LayoutParams(width, AbsListView.LayoutParams.WRAP_CONTENT));
    // Give it a nice background
    //i.setBackgroundResource(R.drawable.picture_frame);
    return i;
}

From source file:Main.java

static public void setImageViewSize(ImageView imageView) {
    ViewGroup.LayoutParams params = imageView.getLayoutParams();
    params.height = 250;/*  www . j  a v  a 2 s .  c o m*/
    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;/*from w  w  w.  java  2  s. c o m*/
    params.width = width;
    imageView.setLayoutParams(params);
    imageView.requestLayout();
}

From source file:Main.java

public static ImageView resizeImageView(int width, int height, ImageView i) {
    //        final ImageView picture1 = (ImageView)findViewById(R.id.imageView1);
    LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(width, height);
    i.setLayoutParams(layoutParams);
    return i;/*from www. java 2s  .c  o m*/
}

From source file:Main.java

private static ImageView newStar(Activity activity, int drawableResId) {
    ImageView star = new ImageView(activity);
    LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.WRAP_CONTENT);
    star.setLayoutParams(params);
    star.setImageResource(drawableResId);
    return star;/*from   ww  w .j a  va 2  s.c  o m*/
}

From source file:com.dm.material.dashboard.candybar.helpers.ViewHelper.java

public static void removeSearchViewSearchIcon(@Nullable View view) {
    if (view != null) {
        ImageView searchIcon = (ImageView) view;
        ViewGroup linearLayoutSearchView = (ViewGroup) view.getParent();
        if (linearLayoutSearchView != null) {
            linearLayoutSearchView.removeView(searchIcon);
            linearLayoutSearchView.addView(searchIcon);

            searchIcon.setAdjustViewBounds(true);
            searchIcon.setMaxWidth(0);/*w  w w.  jav a 2s. co  m*/
            searchIcon.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
                    LinearLayout.LayoutParams.WRAP_CONTENT));
            searchIcon.setImageDrawable(null);
        }
    }
}

From source file:arun.com.chromer.settings.widgets.PreferenceIconLayoutHelper.java

/**
 * Applies layout changes on the preference icon view so that it does not look overly big.
 *
 * @param holder  the preference view holder
 * @param checked if the preference is enabled
 *///from  ww w.  ja va  2s .  c om
static void applyLayoutChanges(@NonNull PreferenceViewHolder holder, boolean checked) {
    try {
        final LinearLayout iconFrame = (LinearLayout) holder
                .findViewById(android.support.v7.preference.R.id.icon_frame);
        final ImageView imageView = (ImageView) holder.findViewById(android.R.id.icon);

        if (iconFrame.getMinimumWidth() != 0) {
            iconFrame.setMinimumWidth(0);
            imageView.setScaleType(ImageView.ScaleType.CENTER);
            LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
                    ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
            int dp12 = Utils.dpToPx(12);
            params.setMargins(dp12, 0, dp12, 0);
            imageView.setLayoutParams(params);
        }

        applyIconTint(imageView, checked);
    } catch (Exception e) {
        Timber.e(e);
    }
}

From source file:com.ouyangzn.github.utils.UiUtils.java

/**
 * toolbar//from w w w  . j  a v  a 2  s  .  c om
 *
 * @param toolbar toolbar
 * @param resId ?id
 * @param gravity ?{@link Gravity#LEFT}?{@link Gravity#RIGHT}
 * @param margin ?{@link Toolbar.LayoutParams#setMargins(int, int, int, int)}
 * @return ImageView
 */
public static ImageView addImage2Toolbar(Toolbar toolbar, int resId, int gravity, int[] margin) {
    Context context = toolbar.getContext();
    ImageView img = new ImageView(context);
    img.setImageResource(resId);
    img.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
    Toolbar.LayoutParams params = new Toolbar.LayoutParams(Toolbar.LayoutParams.WRAP_CONTENT,
            Toolbar.LayoutParams.WRAP_CONTENT);
    params.gravity = gravity | Gravity.CENTER;
    try {
        params.setMargins(margin[0], margin[1], margin[2], margin[3]);
    } catch (Exception e) {
        int margin_15 = ScreenUtils.dp2px(context, 15);
        params.setMargins(margin_15, 0, margin_15, 0);
    }
    img.setLayoutParams(params);
    toolbar.addView(img);
    return img;
}

From source file:io.github.runassudo.ptoffline.utils.TransportrUtils.java

static public void addWalkingBox(Context context, ViewGroup lineLayout, int index) {
    ImageView v = (ImageView) LayoutInflater.from(context).inflate(R.layout.walking_box, lineLayout, false);

    // set margin, because setting in in xml does not work
    FlowLayout.LayoutParams llp = new FlowLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.WRAP_CONTENT);
    llp.setMargins(0, 5, 15, 5);/*w  w w.  j  a v  a 2 s . c o  m*/
    v.setLayoutParams(llp);

    lineLayout.addView(v, index);
}

From source file:de.grobox.liberario.utils.TransportrUtils.java

static public void addWalkingBox(Context context, ViewGroup lineLayout, int index) {
    ImageView v = (ImageView) LayoutInflater.from(context).inflate(R.layout.walking_box, lineLayout, false);

    // set margin, because setting in in xml does not work
    FlowLayout.LayoutParams llp = new FlowLayout.LayoutParams(WRAP_CONTENT, WRAP_CONTENT);
    llp.setMargins(0, 5, 10, 5);//from ww w .ja  v  a  2 s .  c om
    v.setLayoutParams(llp);

    lineLayout.addView(v, index);
}