Example usage for android.widget ImageView setScaleType

List of usage examples for android.widget ImageView setScaleType

Introduction

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

Prototype

public void setScaleType(ScaleType scaleType) 

Source Link

Document

Controls how the image should be resized or moved to match the size of this ImageView.

Usage

From source file:Main.java

public static ImageView createImageViewFromBitmap(Context context, Bitmap bitmap) {
    ImageView imageView = new ImageView(context);
    imageView.setScaleType(ScaleType.FIT_XY);
    imageView.setImageBitmap(bitmap);//from www. ja  v  a  2s.  c om
    return imageView;
}

From source file:Main.java

public static void startActivity(final Activity thisActivity, final Intent intent, final View triggerView,
        int colorOrImageRes, final long durationMills) {
    int[] location = new int[2];
    triggerView.getLocationInWindow(location);
    final int cx = location[0] + triggerView.getWidth();
    final int cy = location[1] + triggerView.getHeight() + (int) TypedValue
            .applyDimension(TypedValue.COMPLEX_UNIT_DIP, 160, thisActivity.getResources().getDisplayMetrics());
    final ImageView view = new ImageView(thisActivity);
    view.setScaleType(ImageView.ScaleType.CENTER_CROP);
    view.setImageResource(colorOrImageRes);
    final ViewGroup decorView = (ViewGroup) thisActivity.getWindow().getDecorView();
    int w = decorView.getWidth();
    int h = decorView.getHeight();
    decorView.addView(view, w, h);//w  ww. j av  a 2  s .co  m
    final int finalRadius = (int) Math.sqrt(w * w + h * h) + 1;
    Animator anim = ViewAnimationUtils.createCircularReveal(view, cx, cy, 0, finalRadius);
    anim.setDuration(durationMills);
    anim.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animation) {
            super.onAnimationEnd(animation);
            thisActivity.startActivity(intent);
            thisActivity.overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out);
        }
    });
    anim.start();
}

From source file:Main.java

public static ImageView getItemImageView(Context context, @DrawableRes int placeholderResId,
        ImageView.ScaleType scaleType) {
    ImageView imageView = new ImageView(context);
    imageView.setImageResource(placeholderResId);
    imageView.setClickable(true);/*from  w  w  w .  j a  v a2s  .  co m*/
    imageView.setScaleType(scaleType);
    return imageView;
}

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

/**
 * toolbar/*from www  .  j av  a2  s.c o  m*/
 *
 * @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:Main.java

public static void addResourceImage(Activity activity, LinearLayout layout, int imgResource, int width,
        int height) {
    ImageView image = new ImageView(activity);
    image.setImageResource(imgResource);
    if (width > 0)
        image.setMaxWidth(width);//from w ww . jav a  2s  . c o  m
    if (height > 0)
        image.setMaxHeight(height);
    image.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
    layout.addView(image);
}

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
 *//*  w  w w .  ja v a2 s. co  m*/
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:org.videolan.vlc.gui.helpers.AsyncImageLoader.java

private static void updateTargetImage(final Bitmap bitmap, final View target, final ViewDataBinding vdb) {
    if (bitmap == null || bitmap.getWidth() <= 1 || bitmap.getHeight() <= 1)
        return;/* w ww.j av a 2s . co  m*/
    if (vdb != null) {
        vdb.setVariable(BR.scaleType, ImageView.ScaleType.FIT_CENTER);
        vdb.setVariable(BR.cover, new BitmapDrawable(VLCApplication.getAppResources(), bitmap));
        vdb.setVariable(BR.protocol, null);
    } else {
        sHandler.post(new Runnable() {
            @Override
            public void run() {
                if (target instanceof ImageView) {
                    ImageView iv = (ImageView) target;
                    iv.setVisibility(View.VISIBLE);
                    iv.setScaleType(ImageView.ScaleType.FIT_CENTER);
                    iv.setImageBitmap(bitmap);
                } else if (target instanceof TextView) {
                    ViewCompat.setBackground(target,
                            new BitmapDrawable(VLCApplication.getAppResources(), bitmap));
                    ((TextView) target).setText(null);
                }
            }
        });
    }
}

From source file:com.maxleap.mall.adapters.ProductGalleryAdapter.java

@Override
public Object instantiateItem(ViewGroup container, int position) {
    ImageView imageView = new ImageView(mContext);
    imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
    String imgUrl = mPics.get(position);
    Picasso.with(mContext).load(imgUrl).into(imageView);
    container.addView(imageView);//ww w . jav  a 2s.c o  m
    return imageView;
}

From source file:com.yanzhenjie.nohttp.sample.adapter.MainBannerAdapter.java

@Override
public Object instantiateItem(ViewGroup container, int position) {
    ImageView imageView = new ImageView(container.getContext());
    imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
    imageView.setImageResource(IMAGES[position % IMAGES.length]);
    container.addView(imageView);//from w  ww.  ja v  a 2s  .  c o  m
    return imageView;
}

From source file:SplashActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_splash);

    ImageView imageView = (ImageView) findViewById(R.id.splash_image);
    imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);

    detector = new GestureDetector(this, new SplashListener());
}