Reputation: 4667
In Kotlin i am getting IDE error saying "Val cannot be reassigned" when i try to set width programmatically, Please see the code written in the onCreate() of Activity class,
shadowView.width = 200
Here shadowView is a View added in the layout
Upvotes: 8
Views: 2462
Reputation: 1387
In order to set a view's width programmatically you should change its width in its layout params, like the example below:
val layoutParams = shadowView.layoutParams
layoutParams.width = 200
shadowView.layoutParams = layoutParams
Upvotes: 3