Does GridView.LayoutParams not exist in Kotlin?

I want to use GridView and according to the documentation in the adapter, I can use this line in the adapter:

  imageView.setLayoutParams(new GridView.LayoutParams(85, 85)); 

Well, transferring him to Kotlin, he says:

enter image description here

It works in Java, but not in Kotlin.

So why? And how can I use GridView.LayoutParams in Kotlin?

+5
source share
2 answers

Try one of the following:

 imageView.setLayoutParams(AbsListView.LayoutParams(85, 85)) imageView.setLayoutParams( GridView@AbsListView.LayoutParams (85, 85)) 

Since GridView does not have its own implementation of LayoutParams, you need to choose the implementation of your superclass AbsListView . You can decide whether you want to add the GridView@ prefix.

+7
source

GridView does not have an inner class LayoutParams , it uses AbsListView.LayoutParams

so just change the code to

 imageView.layoutParams = AbsListView.LayoutParams(85,85) 
+3
source

Source: https://habr.com/ru/post/1271298/


All Articles