Skip to content

Instantly share code, notes, and snippets.

@programmerr47
Created December 28, 2020 12:26
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 programmerr47/73c60c9c466df2fd88dbb55ea83bba0e to your computer and use it in GitHub Desktop.
Save programmerr47/73c60c9c466df2fd88dbb55ea83bba0e to your computer and use it in GitHub Desktop.
val View.padding get() = ViewPadding(this)
inline class ViewPadding(private val view: View) {
var start: Int
get() = view.paddingStart
set(value) = view.setPaddingRelative(value, top, end, bottom)
var top: Int
get() = view.paddingTop
set(value) = view.setPaddingRelative(start, value, end, bottom)
var end: Int
get() = view.paddingEnd
set(value) = view.setPaddingRelative(start, top, value, bottom)
var bottom: Int
get() = view.paddingBottom
set(value) = view.setPaddingRelative(start, top, end, value)
var horizontal: Int
get() = start + end
set(value) {
start = value
end = value
}
var vertical: Int
get() = top + bottom
set(value) {
top = value
bottom = value
}
var total: Int
@Deprecated("No getter for that field", level = DeprecationLevel.HIDDEN)
get() = throw UnsupportedOperationException("No getter for such field")
set(value) {
horizontal = value
vertical = value
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment