Skip to content

Instantly share code, notes, and snippets.

@zaki50
Created June 24, 2012 12:33
Show Gist options
  • Save zaki50/2983097 to your computer and use it in GitHub Desktop.
Save zaki50/2983097 to your computer and use it in GitHub Desktop.
高さと幅がおなじになるView
package org.zakky.square;
import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
public class SquareView extends View {
public SquareView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
public SquareView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public SquareView(Context context) {
super(context);
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
int width = MeasureSpec.getSize(widthMeasureSpec);
int height = MeasureSpec.getSize(heightMeasureSpec);
int smaller = Math.min(width, height);
setMeasuredDimension(smaller, smaller);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment