Created
December 18, 2015 22:16
-
-
Save ElFeesho/a69aba67d8c9287045b2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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