The ViewBinding implementation is unable to render the layout configuration for LinearLayout used in my code, while the same layout works with the older technique of findViewById()
I have setup the gradle to use ViewBinding
android {
...
buildFeatures {
viewBinding = true
}
Below is the activity which uses a LinearLayout
activity_main.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:orientation="vertical"
tools:context=".MainActivity">
<ImageView
... />
<Button
... />
</LinearLayout>
The corresponding Kotlin class includes the binding instance with its root view passed to setContentView()
MainActivity.kt
private lateinit var binding: ActivityMainBinding
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding = ActivityMainBinding.inflate(layoutInflater)
...
setContentView(binding.root)
}
While the Layout editor renders a correct alignment of the app, once it is launched onto the emulator the layout configuration such as center_vertical alignment set using layout_gravity of LinearLayout is ignored.
Is something incorrect or missing the way ViewBinding is implemented?