When I’m trying to implement multiple TextViews in the LinearLayout, the all gravity options are not applied to both horizontal and vertical alignment.
This code block is an example for the Gravity.CENTER option:
optionsContainer.addView(context.linearLayout {

lparams(width = matchParent, height = matchParent)


textView("1") {

gravity = Gravity.CENTER

}.lparams(width = 0, height = matchParent, weight = 1f)


textView("2") {

gravity = Gravity.CENTER

}.lparams(width = 0, height = matchParent, weight = 1f)

})
The FrameLayout of optionsContainer is following:
<FrameLayout

android:id="@+id/options_container"

android:layout_width="match_parent"

android:layout_height="56dp”

android:layout_alignParentBottom="true" />
In my opinion, this problem can be fixed with attached code block below:
inline fun ViewManager.textView(text: CharSequence?, gravity: Int, init: android.widget.TextView.() -> Unit): android.widget.TextView {

return ankoView(`$$Anko$Factories$Sdk23View`.TEXT_VIEW) {

init()

setText(text)

setGravity(gravity)

}

}
Thank you!
+1 on this, I would add that IDEA is completely lost because of this.
I just spent an hour wondering why my text wasn't centered, because IDEA told me I was using the right gravity.
I recommend renaming the layout's gravity to layoutGravity and the textview's gravity to textGravity.
For now, you have to use this.gravity to set the text gravity in a TextView:
textView {
this.gravity = Gravity.CENTER
}
OK! It works for me! Thank you :)
+1 with @Ribesg on the renaming to layoutGravity and textGravity
It working for me. Thanks Dude!
+1 on this, I would add that IDEA is completely lost because of this.
I just spent an hour wondering why my text wasn't centered, because IDEA told me I was using the right gravity.
I recommend renaming the layout's
gravitytolayoutGravityand the textview'sgravitytotextGravity.For now, you have to use
this.gravityto set the text gravity in a TextView:textView { this.gravity = Gravity.CENTER }
hi thank you very much. it's worked for me
Most helpful comment
+1 on this, I would add that IDEA is completely lost because of this.
I just spent an hour wondering why my text wasn't centered, because IDEA told me I was using the right gravity.
I recommend renaming the layout's
gravitytolayoutGravityand the textview'sgravitytotextGravity.For now, you have to use
this.gravityto set the text gravity in a TextView: