android.widget.ImageView.ScaleType Java Examples

The following examples show how to use android.widget.ImageView.ScaleType. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: WelcomeACTIVITY.java    From ALLGO with Apache License 2.0 6 votes vote down vote up
/**
 * 初始化数据
 */
private void initData(){
	//定义一个布局并设置参数
	LinearLayout.LayoutParams mParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
               														  LinearLayout.LayoutParams.MATCH_PARENT);

       //初始化引导图片列表
		ImageView iv0 = new ImageView(this);
		iv0.setScaleType(ScaleType.FIT_CENTER);
		iv0.setLayoutParams(mParams);
           iv0.setImageResource(pics[0]);
           views.add(iv0);
           ImageView iv1 = new ImageView(this);
           iv1.setScaleType(ScaleType.FIT_CENTER);
           iv1.setLayoutParams(mParams);
           iv1.setImageResource(pics[1]); 
           views.add(iv1);
       
       //设置数据
       viewPager.setAdapter(vpAdapter);
       //设置监听
       viewPager.setOnPageChangeListener(this);
       
       //初始化底部小点
       initPoint();
}
 
Example #2
Source File: ImageRequestTest.java    From volley with Apache License 2.0 6 votes vote down vote up
@Test
public void publicMethods() throws Exception {
    // Catch-all test to find API-breaking changes.
    assertNotNull(
            ImageRequest.class.getConstructor(
                    String.class,
                    Response.Listener.class,
                    int.class,
                    int.class,
                    Bitmap.Config.class,
                    Response.ErrorListener.class));
    assertNotNull(
            ImageRequest.class.getConstructor(
                    String.class,
                    Response.Listener.class,
                    int.class,
                    int.class,
                    ImageView.ScaleType.class,
                    Bitmap.Config.class,
                    Response.ErrorListener.class));
    assertEquals(ImageRequest.DEFAULT_IMAGE_TIMEOUT_MS, 1000);
    assertEquals(ImageRequest.DEFAULT_IMAGE_MAX_RETRIES, 2);
    assertEquals(ImageRequest.DEFAULT_IMAGE_BACKOFF_MULT, 2f, 0);
}
 
Example #3
Source File: ButtonFloat.java    From MoeGallery with GNU General Public License v3.0 6 votes vote down vote up
public ButtonFloat(Context context, AttributeSet attrs) {
    super(context, attrs);
    setBackgroundResource(R.drawable.background_button_float);
    setBackgroundColor(backgroundColor);
    sizeRadius = 28;
    setDefaultProperties();
    icon = new ImageView(context);
    icon.setAdjustViewBounds(true);
    icon.setScaleType(ScaleType.CENTER_CROP);
    if (drawableIcon != null) {
        icon.setImageDrawable(drawableIcon);
    }
    RelativeLayout.LayoutParams params =
            new RelativeLayout.LayoutParams(Utils.dpToPx(sizeIcon, getResources()),
                    Utils.dpToPx(sizeIcon, getResources()));
    params.addRule(RelativeLayout.CENTER_IN_PARENT, RelativeLayout.TRUE);
    icon.setLayoutParams(params);
    addView(icon);

}
 
Example #4
Source File: RotateLoadingLayout.java    From FacebookNewsfeedSample-Android with Apache License 2.0 6 votes vote down vote up
public RotateLoadingLayout(Context context, Mode mode, Orientation scrollDirection, TypedArray attrs) {
	super(context, mode, scrollDirection, attrs);

	mRotateDrawableWhilePulling = attrs.getBoolean(R.styleable.PullToRefresh_ptrRotateDrawableWhilePulling, true);

	mHeaderImage.setScaleType(ScaleType.MATRIX);
	mHeaderImageMatrix = new Matrix();
	mHeaderImage.setImageMatrix(mHeaderImageMatrix);

	mRotateAnimation = new RotateAnimation(0, 720, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF,
			0.5f);
	mRotateAnimation.setInterpolator(ANIMATION_INTERPOLATOR);
	mRotateAnimation.setDuration(ROTATION_ANIMATION_DURATION);
	mRotateAnimation.setRepeatCount(Animation.INFINITE);
	mRotateAnimation.setRepeatMode(Animation.RESTART);
}
 
Example #5
Source File: RotateLoadingLayout.java    From bmob-android-demo-paging with GNU General Public License v3.0 6 votes vote down vote up
public RotateLoadingLayout(Context context, Mode mode, Orientation scrollDirection, TypedArray attrs) {
	super(context, mode, scrollDirection, attrs);

	mRotateDrawableWhilePulling = attrs.getBoolean(R.styleable.PullToRefresh_ptrRotateDrawableWhilePulling, true);

	mHeaderImage.setScaleType(ScaleType.MATRIX);
	mHeaderImageMatrix = new Matrix();
	mHeaderImage.setImageMatrix(mHeaderImageMatrix);

	mRotateAnimation = new RotateAnimation(0, 720, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF,
			0.5f);
	mRotateAnimation.setInterpolator(ANIMATION_INTERPOLATOR);
	mRotateAnimation.setDuration(ROTATION_ANIMATION_DURATION);
	mRotateAnimation.setRepeatCount(Animation.INFINITE);
	mRotateAnimation.setRepeatMode(Animation.RESTART);
}
 
Example #6
Source File: FlipLoadingLayout.java    From FanXin-based-HuanXin with GNU General Public License v2.0 6 votes vote down vote up
@Override
protected void onLoadingDrawableSet(Drawable imageDrawable) {
	if (null != imageDrawable) {
		final int dHeight = imageDrawable.getIntrinsicHeight();
		final int dWidth = imageDrawable.getIntrinsicWidth();

		/**
		 * We need to set the width/height of the ImageView so that it is
		 * square with each side the size of the largest drawable dimension.
		 * This is so that it doesn't clip when rotated.
		 */
		ViewGroup.LayoutParams lp = mHeaderImage.getLayoutParams();
		lp.width = lp.height = Math.max(dHeight, dWidth);
		mHeaderImage.requestLayout();

		/**
		 * We now rotate the Drawable so that is at the correct rotation,
		 * and is centered.
		 */
		mHeaderImage.setScaleType(ScaleType.MATRIX);
		Matrix matrix = new Matrix();
		matrix.postTranslate((lp.width - dWidth) / 2f, (lp.height - dHeight) / 2f);
		matrix.postRotate(getDrawableRotationAngle(), lp.width / 2f, lp.height / 2f);
		mHeaderImage.setImageMatrix(matrix);
	}
}
 
Example #7
Source File: RotateLoadingLayout.java    From Favorite-Android-Client with Apache License 2.0 6 votes vote down vote up
public RotateLoadingLayout(Context context, Mode mode, Orientation scrollDirection, TypedArray attrs) {
	super(context, mode, scrollDirection, attrs);

	mRotateDrawableWhilePulling = attrs.getBoolean(R.styleable.PullToRefresh_ptrRotateDrawableWhilePulling, true);

	mHeaderImage.setScaleType(ScaleType.MATRIX);
	mHeaderImageMatrix = new Matrix();
	mHeaderImage.setImageMatrix(mHeaderImageMatrix);

	mRotateAnimation = new RotateAnimation(0, 720, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF,
			0.5f);
	mRotateAnimation.setInterpolator(ANIMATION_INTERPOLATOR);
	mRotateAnimation.setDuration(ROTATION_ANIMATION_DURATION);
	mRotateAnimation.setRepeatCount(Animation.INFINITE);
	mRotateAnimation.setRepeatMode(Animation.RESTART);
}
 
Example #8
Source File: ImageRequest.java    From volley with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a new image request, decoding to a maximum specified width and height. If both width
 * and height are zero, the image will be decoded to its natural size. If one of the two is
 * nonzero, that dimension will be clamped and the other one will be set to preserve the image's
 * aspect ratio. If both width and height are nonzero, the image will be decoded to be fit in
 * the rectangle of dimensions width x height while keeping its aspect ratio.
 *
 * @param url URL of the image
 * @param listener Listener to receive the decoded bitmap
 * @param maxWidth Maximum width to decode this bitmap to, or zero for none
 * @param maxHeight Maximum height to decode this bitmap to, or zero for none
 * @param scaleType The ImageViews ScaleType used to calculate the needed image size.
 * @param decodeConfig Format to decode the bitmap to
 * @param errorListener Error listener, or null to ignore errors
 */
public ImageRequest(
        String url,
        Response.Listener<Bitmap> listener,
        int maxWidth,
        int maxHeight,
        ScaleType scaleType,
        Config decodeConfig,
        @Nullable Response.ErrorListener errorListener) {
    super(Method.GET, url, errorListener);
    setRetryPolicy(
            new DefaultRetryPolicy(
                    DEFAULT_IMAGE_TIMEOUT_MS,
                    DEFAULT_IMAGE_MAX_RETRIES,
                    DEFAULT_IMAGE_BACKOFF_MULT));
    mListener = listener;
    mDecodeConfig = decodeConfig;
    mMaxWidth = maxWidth;
    mMaxHeight = maxHeight;
    mScaleType = scaleType;
}
 
Example #9
Source File: AppPickerPreference.java    From GravityBox with Apache License 2.0 6 votes vote down vote up
@Override
protected void onBindView(View view) {
    super.onBindView(view);

    LinearLayout widgetFrameView = ((LinearLayout) view.findViewById(android.R.id.widget_frame));
    mBtnAppIcon = new ImageButton(mContext);
    LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(mAppIconPreviewSizePx, mAppIconPreviewSizePx);
    lp.gravity = Gravity.CENTER;
    mBtnAppIcon.setLayoutParams(lp);
    mBtnAppIcon.setScaleType(ScaleType.CENTER_CROP);
    mBtnAppIcon.setImageDrawable(mAppInfo.icon);
    mBtnAppIcon.setFocusable(false);
    if (mIconPickerEnabled) {
        mBtnAppIcon.setOnClickListener(this);
        mBtnAppIcon.setOnLongClickListener(this);
    } else {
        mBtnAppIcon.setEnabled(false);
    }
    widgetFrameView.addView(mBtnAppIcon);
    widgetFrameView.setVisibility(View.VISIBLE);
}
 
Example #10
Source File: PhotoViewAttacher.java    From jmessage-android-uikit with MIT License 5 votes vote down vote up
@Override
public final void setScaleType(ScaleType scaleType) {
	if (isSupportedScaleType(scaleType) && scaleType != mScaleType) {
		mScaleType = scaleType;

		// Finally update
		update();
	}
}
 
Example #11
Source File: ImageLoader.java    From SaveVolley with Apache License 2.0 5 votes vote down vote up
protected Request<Bitmap> makeImageRequest(String requestUrl, int maxWidth, int maxHeight, ScaleType scaleType, final String cacheKey) {
    return new ImageRequest(requestUrl, new Listener<Bitmap>() {
        @Override public void onResponse(Bitmap response) {
            onGetImageSuccess(cacheKey, response);
        }
    }, maxWidth, maxHeight, scaleType, Config.RGB_565, new ErrorListener() {
        @Override public void onErrorResponse(VolleyError error) {
            onGetImageError(cacheKey, error);
        }
    });
}
 
Example #12
Source File: PhotoViewAttacher.java    From UltimateAndroid with Apache License 2.0 5 votes vote down vote up
private void checkImageViewScaleType() {
    ImageView imageView = getImageView();

    /**
     * PhotoView's getScaleType() will just divert to this.getScaleType() so
     * only call if we're not attached to a PhotoView.
     */
    if (null != imageView && !(imageView instanceof IPhotoView)) {
        if (!ScaleType.MATRIX.equals(imageView.getScaleType())) {
            throw new IllegalStateException(
                    "The ImageView's ScaleType has been changed since attaching a PhotoViewAttacher");
        }
    }
}
 
Example #13
Source File: PicViewerPage.java    From fingerpoetry-android with Apache License 2.0 5 votes vote down vote up
public void onCreate() {
	activity.getWindow().setBackgroundDrawable(new ColorDrawable(0x4c000000));

	sivViewer = new ScaledImageView(activity);
	sivViewer.setScaleType(ScaleType.MATRIX);
	activity.setContentView(sivViewer);
	if (pic != null) {
		sivViewer.getViewTreeObserver().addOnGlobalLayoutListener(this);
	}
}
 
Example #14
Source File: PicViewerPage.java    From Mobike with Apache License 2.0 5 votes vote down vote up
public void onCreate() {
	activity.getWindow().setBackgroundDrawable(new ColorDrawable(0x4c000000));

	sivViewer = new ScaledImageView(activity);
	sivViewer.setScaleType(ScaleType.MATRIX);
	activity.setContentView(sivViewer);
	if (pic != null) {
		sivViewer.getViewTreeObserver().addOnGlobalLayoutListener(this);
	}
}
 
Example #15
Source File: CropPhotoViewAttacher.java    From ImageSelector with Apache License 2.0 5 votes vote down vote up
@Override
public void setScaleType(ScaleType scaleType) {
 if (isSupportedScaleType(scaleType) && scaleType != mScaleType) {
  mScaleType = scaleType;

  // Finally update
  update();
 }
}
 
Example #16
Source File: Kanner.java    From foodie-app with Apache License 2.0 5 votes vote down vote up
private void initImgFromRes(int[] imagesRes) {
        count = imagesRes.length;
        for (int i = 0; i < count; i++) {
            ImageView iv_dot = new ImageView(context);
            LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
                    LinearLayout.LayoutParams.WRAP_CONTENT,
                    LinearLayout.LayoutParams.WRAP_CONTENT);
            params.leftMargin = 5;
            params.rightMargin = 5;
            iv_dot.setImageResource(R.drawable.dot_blur);
            ll_dot.addView(iv_dot, params);
            iv_dots.add(iv_dot);
        }
        iv_dots.get(0).setImageResource(R.drawable.dot_focus);

        for (int i = 0; i <= count + 1; i++) {
            ImageView iv = new ImageView(context);
            iv.setScaleType(ScaleType.FIT_XY);
//            iv.setBackgroundResource(R.drawable.loading);
            if (i == 0) {
                iv.setImageResource(imagesRes[count - 1]);
            } else if (i == count + 1) {
                iv.setImageResource(imagesRes[0]);
            } else {
                iv.setImageResource(imagesRes[i - 1]);
            }
            imageViews.add(iv);
        }
    }
 
Example #17
Source File: PhotoViewAttacher.java    From o2oa with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public final void setScaleType(ScaleType scaleType) {
	if (isSupportedScaleType(scaleType) && scaleType != mScaleType) {
		mScaleType = scaleType;

		// Finally update
		update();
	}
}
 
Example #18
Source File: PhotoViewAttacher.java    From Tweetin with Apache License 2.0 5 votes vote down vote up
/**
 * Set's the ImageView's ScaleType to Matrix.
 */
private static void setImageViewScaleTypeMatrix(ImageView imageView) {
    /**
     * PhotoView sets it's own ScaleType to Matrix, then diverts all calls
     * setScaleType to this.setScaleType automatically.
     */
    if (null != imageView && !(imageView instanceof IPhotoView)) {
        if (!ScaleType.MATRIX.equals(imageView.getScaleType())) {
            imageView.setScaleType(ScaleType.MATRIX);
        }
    }
}
 
Example #19
Source File: SlidingTab.java    From CSipSimple with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Constructor
 * 
 * @param parent
 *            the container view of this one
 * @param tabId
 *            drawable for the tab
 * @param barId
 *            drawable for the bar
 * @param targetId
 *            drawable for the target
 */
Slider(ViewGroup parent, int iconId, int targetId, int barId, int tabId) {
	// Create tab
	tab = new ImageView(parent.getContext());
	tab.setBackgroundResource(tabId);
	tab.setImageResource(iconId);
	tab.setScaleType(ScaleType.CENTER);
	tab.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));

	// Create hint TextView
	text = new TextView(parent.getContext());
	text.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT));
	text.setBackgroundResource(barId);
	if(!parent.isInEditMode()) {
	    text.setTextAppearance(parent.getContext(), R.style.TextAppearance_SlidingTabNormal);
	}
	
	// Create target
	target = new ImageView(parent.getContext());
	target.setImageResource(targetId);
	target.setScaleType(ScaleType.CENTER);
	target.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
	target.setVisibility(View.INVISIBLE);
	
	
	// this needs to be first - relies on painter's algorithm
	parent.addView(target); 
	parent.addView(tab);
	parent.addView(text);
}
 
Example #20
Source File: PhotoViewAttacher.java    From zen4android with MIT License 5 votes vote down vote up
/**
 * @return true if the ScaleType is supported.
 */
private static boolean isSupportedScaleType(final ScaleType scaleType) {
    if (null == scaleType) {
        return false;
    }

    switch (scaleType) {
        case MATRIX:
            throw new IllegalArgumentException(scaleType.name()
                    + " is not supported in PhotoView");

        default:
            return true;
    }
}
 
Example #21
Source File: NetworkImageViewTest.java    From product-emm with Apache License 2.0 5 votes vote down vote up
public ImageContainer get(String requestUrl, ImageListener imageListener, int maxWidth,
        int maxHeight, ScaleType scaleType) {
    lastRequestUrl = requestUrl;
    lastMaxWidth = maxWidth;
    lastMaxHeight = maxHeight;
    return null;
}
 
Example #22
Source File: PhotoViewAttacher.java    From FanXin-based-HuanXin with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Set's the ImageView's ScaleType to Matrix.
 */
private static void setImageViewScaleTypeMatrix(ImageView imageView) {
	if (null != imageView) {
		if (imageView instanceof PhotoView) {
			/**
			 * PhotoView sets it's own ScaleType to Matrix, then diverts all
			 * calls setScaleType to this.setScaleType. Basically we don't
			 * need to do anything here
			 */
		} else {
			imageView.setScaleType(ScaleType.MATRIX);
		}
	}
}
 
Example #23
Source File: Slider.java    From AlarmOn with Apache License 2.0 5 votes vote down vote up
public Slider(Context context, AttributeSet attrs, int defStyle) {
  super(context, attrs, defStyle);
  // Setup the background which 'holds' the slider.
  tray = new TextView(getContext());
  tray.setBackgroundResource(R.drawable.slider_background);
  tray.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
  tray.setGravity(Gravity.CENTER);

  if (Build.VERSION.SDK_INT < 23) {
      tray.setTextAppearance(getContext(), R.style.SliderText);
  } else {
      tray.setTextAppearance(R.style.SliderText);
  }

  tray.setText(R.string.dismiss);
  addView(tray);

  // Setup the object which will be slid.
  dot = new ImageView(getContext());
  dot.setImageResource(R.drawable.ic_forward);
  dot.setBackgroundResource(R.drawable.slider_btn);
  dot.setScaleType(ScaleType.CENTER);
  dot.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
  dot.setPadding(30, 10, 25, 15);
  addView(dot);

  reset();
}
 
Example #24
Source File: NetworkImageViewTest.java    From product-emm with Apache License 2.0 5 votes vote down vote up
public ImageContainer get(String requestUrl, ImageListener imageListener, int maxWidth,
        int maxHeight, ScaleType scaleType) {
    lastRequestUrl = requestUrl;
    lastMaxWidth = maxWidth;
    lastMaxHeight = maxHeight;
    return null;
}
 
Example #25
Source File: RoundedDrawable.java    From BigApp_Discuz_Android with Apache License 2.0 5 votes vote down vote up
public RoundedDrawable setScaleType(ScaleType scaleType) {
  if (scaleType == null) {
    scaleType = ScaleType.FIT_CENTER;
  }
  if (mScaleType != scaleType) {
    mScaleType = scaleType;
    updateShaderMatrix();
  }
  return this;
}
 
Example #26
Source File: CanvasProfileActivity.java    From DeviceConnect-Android with MIT License 5 votes vote down vote up
/**
 * 画面を更新します.
 * @param drawObj 更新する画像データ
 */
private void showDrawObject(final CanvasDrawImageObject drawObj) {
    switch (drawObj.getMode()) {
        default:
        case NON_SCALE_MODE:
            Matrix matrix = new Matrix();
            matrix.postTranslate((float) drawObj.getX(), (float) drawObj.getY());
            mCanvasView.setImageBitmap(mBitmap);
            mCanvasView.setScaleType(ScaleType.MATRIX);
            mCanvasView.setImageMatrix(matrix);
            break;
        case SCALE_MODE:
            mCanvasView.setImageBitmap(mBitmap);
            mCanvasView.setScaleType(ScaleType.FIT_CENTER);
            mCanvasView.setTranslationX((int) drawObj.getX());
            mCanvasView.setTranslationY((int) drawObj.getY());
            break;
        case FILL_MODE:
            BitmapDrawable bd = new BitmapDrawable(getResources(), mBitmap);
            bd.setTileModeX(Shader.TileMode.REPEAT);
            bd.setTileModeY(Shader.TileMode.REPEAT);
            mCanvasView.setImageDrawable(bd);
            mCanvasView.setScaleType(ScaleType.FIT_XY);
            mCanvasView.setTranslationX((int) drawObj.getX());
            mCanvasView.setTranslationY((int) drawObj.getY());
            break;
    }
}
 
Example #27
Source File: PhotoViewAttacher.java    From light-novel-library_Wenku8_Android with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void setScaleType(ScaleType scaleType) {
    if (isSupportedScaleType(scaleType) && scaleType != mScaleType) {
        mScaleType = scaleType;

        // Finally update
        update();
    }
}
 
Example #28
Source File: ImageLoader.java    From volley_demo with Apache License 2.0 5 votes vote down vote up
protected Request<Bitmap> makeImageRequest(String requestUrl, int maxWidth, int maxHeight,
        ScaleType scaleType, final String cacheKey) {
    return new ImageRequest(requestUrl, new Listener<Bitmap>() {
        @Override
        public void onResponse(Bitmap response) {
            onGetImageSuccess(cacheKey, response);
        }
    }, maxWidth, maxHeight, scaleType, Config.RGB_565, new ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {
            onGetImageError(cacheKey, error);
        }
    });
}
 
Example #29
Source File: ImageLoader.java    From SaveVolley with Apache License 2.0 5 votes vote down vote up
protected Request<Bitmap> makeImageRequest(String requestUrl, int maxWidth, int maxHeight, ScaleType scaleType, final String cacheKey) {
    return new ImageRequest(requestUrl, new Listener<Bitmap>() {
        @Override public void onResponse(Bitmap response) {
            onGetImageSuccess(cacheKey, response);
        }
    }, maxWidth, maxHeight, scaleType, Config.RGB_565, new ErrorListener() {
        @Override public void onErrorResponse(VolleyError error) {
            onGetImageError(cacheKey, error);
        }
    });
}
 
Example #30
Source File: MainFrameActivity.java    From pixate-freestyle-android with Apache License 2.0 5 votes vote down vote up
/**
 * Convenient method to add a tab to the tab widget at bottom.
 * 
 * @param resId The resource id of image shown on indicator
 * @param content The class type of content
 */
private void addTab(int resId, Class<? extends Fragment> content) {
    ImageView indicator = new ImageView(this);
    indicator.setScaleType(ScaleType.CENTER_INSIDE);
    indicator.setBackgroundResource(R.drawable.tab_bg);
    indicator.setImageResource(resId);
    TabSpec spec = tabHost.newTabSpec(content.getSimpleName()).setIndicator(indicator);
    tabHost.addTab(spec, content, null);
}