From 902d2c77efd9f01eaa043538993f50fbae745ec1 Mon Sep 17 00:00:00 2001 From: Severiano Jaramillo Date: Wed, 24 Jan 2018 23:21:04 -0600 Subject: [PATCH] Created SquaredImageView --- .../crystalwallet/util/SquaredImageView.java | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 app/src/main/java/cy/agorise/crystalwallet/util/SquaredImageView.java diff --git a/app/src/main/java/cy/agorise/crystalwallet/util/SquaredImageView.java b/app/src/main/java/cy/agorise/crystalwallet/util/SquaredImageView.java new file mode 100644 index 0000000..8d984a0 --- /dev/null +++ b/app/src/main/java/cy/agorise/crystalwallet/util/SquaredImageView.java @@ -0,0 +1,33 @@ +package cy.agorise.crystalwallet.util; + +import android.content.Context; +import android.support.annotation.Nullable; +import android.support.v7.widget.AppCompatImageView; +import android.util.AttributeSet; + +/** + * Created by xd on 1/24/18. + * ImageView which adjusts its size to always create a square + */ + +public class SquaredImageView extends AppCompatImageView { + public SquaredImageView(Context context) { + super(context); + } + + public SquaredImageView(Context context, @Nullable AttributeSet attrs) { + super(context, attrs); + } + + public SquaredImageView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) { + super(context, attrs, defStyleAttr); + } + + @Override + protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { + super.onMeasure(widthMeasureSpec, heightMeasureSpec); + + int size = Math.min(getMeasuredWidth(), getMeasuredHeight()); + setMeasuredDimension(size, size); + } +}