Skip to content

Instantly share code, notes, and snippets.

@alphamu
Created September 16, 2013 05:46
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alphamu/6577060 to your computer and use it in GitHub Desktop.
Save alphamu/6577060 to your computer and use it in GitHub Desktop.
Android LinearLayout with the same height as width.
import android.content.Context;
import android.util.AttributeSet;
import android.widget.LinearLayout;
public class SquareLinearLayout extends LinearLayout {
public SquareLinearLayout(Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, widthMeasureSpec);
// or you can use this if you want the square to use height as it basis
// super.onMeasure(heightMeasureSpec, heightMeasureSpec);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment