7

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?

Community
  • 1
  • 1
Amiraslan
  • 794
  • 1
  • 8
  • 19
  • 3
    Related: https://stackoverflow.com/questions/45703751/how-to-set-layout-params-on-an-imageview-inside-gridview-in-android – BakaWaii Aug 28 '17 at 13:47

2 Answers2

8

Try one of the following:

imageView.setLayoutParams(AbsListView.LayoutParams(85, 85))
imageView.setLayoutParams(GridView@AbsListView.LayoutParams(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.

dipdipdip
  • 2,326
  • 1
  • 21
  • 31
4

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

so just change code to

imageView.layoutParams = AbsListView.LayoutParams(85,85)
Andrey Danilov
  • 6,194
  • 5
  • 32
  • 56