Skip to content

Instantly share code, notes, and snippets.

@achillesrasquinha
Last active December 8, 2015 06:10
Show Gist options
  • Save achillesrasquinha/f393eae87748a57afed2 to your computer and use it in GitHub Desktop.
Save achillesrasquinha/f393eae87748a57afed2 to your computer and use it in GitHub Desktop.
Android Square Layout

Android Square Layout

java

package <your_package_name>

import android.annotation.TargetApi;
import android.content.Context;
import android.os.Build;
import android.util.AttributeSet;
import android.widget.RelativeLayout;

public class SquareLayout extends RelativeLayout {

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

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

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

  @TargetApi(Build.VERSION_CODES.LOLLIPOP)
  public SquareLayout(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
    super(context, attrs, defStyleAttr, defStyleRes);
  }

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

xml

<your_package_name.SquareLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content">
    
    <!--
        your layouts/views/widgets
    -->
    
</your_pacakge_name.SquareLayout>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment