Guest User

Untitled

a guest
Nov 17th, 2018
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.81 KB | None | 0 0
  1.  
  2. package org.zakky.square;
  3.  
  4. import android.content.Context;
  5. import android.util.AttributeSet;
  6. import android.view.View;
  7.  
  8. public class SquareView extends View {
  9.  
  10. public SquareView(Context context, AttributeSet attrs, int defStyle) {
  11. super(context, attrs, defStyle);
  12. }
  13.  
  14. public SquareView(Context context, AttributeSet attrs) {
  15. super(context, attrs);
  16. }
  17.  
  18. public SquareView(Context context) {
  19. super(context);
  20. }
  21.  
  22. @Override
  23. protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
  24. super.onMeasure(widthMeasureSpec, heightMeasureSpec);
  25.  
  26. int width = MeasureSpec.getSize(widthMeasureSpec);
  27. int height = MeasureSpec.getSize(heightMeasureSpec);
  28.  
  29. int smaller = Math.min(width, height);
  30.  
  31. setMeasuredDimension(smaller, smaller);
  32. }
  33.  
  34. }
Add Comment
Please, Sign In to add comment