Created
June 24, 2012 12:33
-
-
Save zaki50/2983097 to your computer and use it in GitHub Desktop.
高さと幅がおなじになるView
This file contains 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 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