Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GridView.LayoutParams doesn't exist in Kotlin?

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

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

Well, converting it to Kotlin, it says:

enter image description here

It works in Java, but not in Kotlin.

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

like image 492
Amiraslan Avatar asked Aug 28 '17 13:08

Amiraslan


2 Answers

Try one of the following:

imageView.setLayoutParams(AbsListView.LayoutParams(85, 85))
imageView.setLayoutParams([email protected](85, 85))

Since GridView doesn't have it's own implementation of LayoutParams you have to choose an implementation of its superclass AbsListView. You can decide if you want to add the GridView@ prefix.

like image 193
dipdipdip Avatar answered Oct 12 '22 13:10

dipdipdip


GridView doesnt have inner class LayoutParams, it uses AbsListView.LayoutParams

so just change code to

imageView.layoutParams = AbsListView.LayoutParams(85,85)
like image 4
Andrey Danilov Avatar answered Oct 12 '22 12:10

Andrey Danilov