Skip to content

Instantly share code, notes, and snippets.

@ElFeesho
Created December 18, 2015 22:16
Show Gist options
  • Select an option

  • Save ElFeesho/a69aba67d8c9287045b2 to your computer and use it in GitHub Desktop.

Select an option

Save ElFeesho/a69aba67d8c9287045b2 to your computer and use it in GitHub Desktop.
package uk.czcz.themeingtest;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Matrix;
import android.util.AttributeSet;
import android.widget.ImageView;
public class ProfileImageView extends ImageView {
public ProfileImageView(Context context) {
this(context, null, 0);
}
public ProfileImageView(Context context, AttributeSet attrs) {
this(context, attrs, 0);
}
public ProfileImageView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
@Override
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
super.onSizeChanged(w, h, oldw, oldh);
Matrix matrix = new Matrix();
float sx = (getMeasuredWidth() / (float) getDrawable().getIntrinsicWidth());
matrix.setScale(sx, sx);
matrix.postTranslate(0, (-(h * sx) / 2));
setImageMatrix(matrix);
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
canvas.drawColor(0x880088ff);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment