I would like to set the height and width of an video view to match_parent. My code looks something like the following. It works without the height and width attributes, but doing it as below give me a val cannot be reassigned error.
class VideoActivityUI : AnkoComponent<VideoActivity> {
companion object {
val ID_VIDEO = 11
}
override fun createView(ui: AnkoContext<VideoActivity>) = with(ui) {
videoView{
id = ID_VIDEO
height = matchParent
width = matchParent
}
}
}
You have to use lparams to set layout parameters, like this (you can omit the explicit parameter names if you want to):
videoView {
id = ID_VIDEO
}.lparams (width = matchParent, height = matchParent)
Alternatively, you can do it like this:
videoView {
id = ID_VIDEO
}.lparams {
height = matchParent
width = matchParent
}
The related wiki section for Anko can be found here.
Note that you have to have a ViewGroup around your VideoView as the root of the Activity's layout for it to have layout parameters available, because it gets different ones depending on whether it's in a FrameLayout, LinearLayout, or RelativeLayout.
For example, with a simple frameLayout, your code would look like this:
override fun createView(ui: AnkoContext<VideoActivity>) = with(ui) {
frameLayout {
videoView {
id = ID_VIDEO
}.lparams(matchParent, matchParent)
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With