Skip to content

Instantly share code, notes, and snippets.

@momvart
Created April 3, 2020 15:15
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 momvart/546ba76052c65027cd4a3e7847fb784d to your computer and use it in GitHub Desktop.
Save momvart/546ba76052c65027cd4a3e7847fb784d to your computer and use it in GitHub Desktop.
Android binding adapter for `layout_gravity` attribute
@BindingAdapter("android:layout_gravity")
fun setLayoutGravity(view: View, gravity: Int) {
when (view.layoutParams) {
is LinearLayout.LayoutParams ->
(view.layoutParams as LinearLayout.LayoutParams).gravity = gravity
is FrameLayout.LayoutParams ->
(view.layoutParams as FrameLayout.LayoutParams).gravity = gravity
//Add more view groups here
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment