Skip to content

Instantly share code, notes, and snippets.

@cscouto
Created April 9, 2018 23:26
Show Gist options
  • Save cscouto/328d1e03f90c3c8245f3ef7be36786a5 to your computer and use it in GitHub Desktop.
Save cscouto/328d1e03f90c3c8245f3ef7be36786a5 to your computer and use it in GitHub Desktop.
KOTLIN - Class to make a squared size item for you recyclerview grid layout
import android.annotation.TargetApi
import android.content.Context
import android.os.Build
import android.util.AttributeSet
import android.widget.RelativeLayout
/**
* Created by docouto on 4/9/18.
*/
class SquareLayout : RelativeLayout {
constructor(context: Context) : super(context) {}
constructor(context: Context, attrs: AttributeSet) : super(context, attrs) {}
constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int) : super(context, attrs, defStyleAttr) {}
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int, defStyleRes: Int) : super(context, attrs, defStyleAttr, defStyleRes) {
}
override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) {
// Set a square layout.
super.onMeasure(widthMeasureSpec, widthMeasureSpec)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment