Skip to content

Instantly share code, notes, and snippets.

@tizisdeepan
Created April 22, 2019 12:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tizisdeepan/aa002dac72a3902ca3e0088bccf46061 to your computer and use it in GitHub Desktop.
Save tizisdeepan/aa002dac72a3902ca3e0088bccf46061 to your computer and use it in GitHub Desktop.
SquareLayout makes sure that the view appears to be a square at all times no matter what it's attributes and children are.
import android.content.Context
import android.util.AttributeSet
import android.widget.FrameLayout
class SquareLayout : FrameLayout {
constructor(context: Context) : super(context)
constructor(context: Context, attrs: AttributeSet) : super(context, attrs)
constructor(context: Context, attrs: AttributeSet, defStyle: Int) : super(context, attrs, defStyle)
public override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) {
super.onMeasure(widthMeasureSpec, widthMeasureSpec)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment