Created
April 3, 2020 15:15
-
-
Save momvart/546ba76052c65027cd4a3e7847fb784d to your computer and use it in GitHub Desktop.
Android binding adapter for `layout_gravity` attribute
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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