icarapovic
1/26/2017 - 6:58 PM

Square View

A view that will always be a square, using the width as width and height size.

class WidthDefinedAlbumArtView @JvmOverloads constructor(
    context: Context,
    attrs: AttributeSet? = null,
    defStyle: Int = 0
) : AppCompatImageView(context, attrs, defStyle) {

    override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) {
        // proceed only with width so we get a square, ignore height
        super.onMeasure(widthMeasureSpec, widthMeasureSpec)
    }
}