Skip to content

Instantly share code, notes, and snippets.

@marius-m
Created May 20, 2022 09:09
Show Gist options
  • Save marius-m/caa284e736bf14db0adba233d953c017 to your computer and use it in GitHub Desktop.
Save marius-m/caa284e736bf14db0adba233d953c017 to your computer and use it in GitHub Desktop.
Dynamically apply padding to view. Useful in RecyclerView with comples item composition.
/**
* Dynamically applies padding
*/
fun View?.applyPadding(
paddingStart: Int? = null,
paddingEnd: Int? = null,
paddingTop: Int? = null,
paddingBottom: Int? = null,
) {
this?.setPadding(
paddingStart ?: this.paddingStart,
paddingTop ?: this.paddingTop,
paddingEnd ?: this.paddingEnd,
paddingBottom ?: this.paddingBottom,
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment