Skip to content

Instantly share code, notes, and snippets.

@xingrz
Last active October 12, 2021 21:25
Show Gist options
  • Select an option

  • Save xingrz/c95cdedf57f45f60dd28 to your computer and use it in GitHub Desktop.

Select an option

Save xingrz/c95cdedf57f45f60dd28 to your computer and use it in GitHub Desktop.

Revisions

  1. xingrz revised this gist Nov 23, 2014. 1 changed file with 0 additions and 2 deletions.
    2 changes: 0 additions & 2 deletions !.md
    Original file line number Diff line number Diff line change
    @@ -1,2 +0,0 @@
    SquareImageView
    ==========
  2. xingrz created this gist Nov 23, 2014.
    2 changes: 2 additions & 0 deletions !.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,2 @@
    SquareImageView
    ==========
    27 changes: 27 additions & 0 deletions SquareImageView.java
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,27 @@
    import android.content.Context;
    import android.util.AttributeSet;
    import android.widget.ImageView;

    public class SquareImageView extends ImageView {

    public SquareImageView(Context context) {
    super(context);
    }

    public SquareImageView(Context context, AttributeSet attrs) {
    super(context, attrs);
    }

    public SquareImageView(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);
    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    super.onMeasure(widthMeasureSpec, heightMeasureSpec);

    int width = getMeasuredWidth();
    setMeasuredDimension(width, width);
    }

    }