Thursday, 28 March 2019

HorizontalGridView with CardViewPresenter (Android TV)

I want to achieve an horizontal list of cards (netflix style) on Android TV.

I'm using an HorizontalGridView with a CardViewPresenter and I cannot be able to display more than 1 card at a time.

Here is the part of code I'm calling to do it.

rootView.findViewById<HorizontalGridView>(R.id.home_live_horizontalgridview).apply {
  val mRowsAdapter = ArrayObjectAdapter(ListRowPresenter())

  val presenterSelector = ImageCardViewPresenter(requireContext())
  liveListRowAdapter = ArrayObjectAdapter(presenterSelector)
  liveListRowAdapter?.addAll(0, myItems)

  mRowsAdapter.add(ListRow(liveListRowAdapter))

  val bridgeAdapter = ItemBridgeAdapter()
  bridgeAdapter.setAdapter(mRowsAdapter)
  adapter = bridgeAdapter
}

The problem has nothing to do with margin or layout_width/height because if I use a custom adapter like this, it works well on the full line.

rootView.findViewById<HorizontalGridView>(R.id.home_live_horizontalgridview).apply {
  adapter = CardAdapter(context, R.layout.list_element_mainaction, audienceShows, Constants.LINE_AUDIENCE, this@HomeFragment)
}  

I've based my development on android tv showcase, except that I don't want to use a BrowseFragment and be too limited for further design implementation. Here is the link to the Google sample.

Any idea ? Thanks a lot



from HorizontalGridView with CardViewPresenter (Android TV)

No comments:

Post a Comment