In a course of developing an Android app, something happened to show the user a list of items. If you are looking at a mobile phone vertically, the number of rows are not limited, but if you are looking horizontally, you want to create a function that allows you to adjust the number of columns according to the width. This is the code I am currently using.
class MainActivity : AppCompatActivity() {
var array: ArrayList<String>? = null
override fun onCreate(savedInstanceState: Bundle?) {
...
...
recyclerView.layoutManager = GirdLayoutManager(this, 2)
recyclerView.setHasFixedSize(true)
recyclerView.adapter = MyAdapter(array!!)
}
}
Since the value of spanCount is set to 2, of course, I know that the number of columns is set to 2. I just want the width of the itemView I want to show is properly adjusted according to the mobile width. Is there any solution?
If you need a custom GridLayout manager, how do you make it?
