2

I'm currently developing an Android TV app. I find it challenging because you can't just draw a list and have the user navigate with touch. You have to programmatically scroll the list when the user hits the Dpad buttons.

I would like to create a list that is similar to the menus in the Settings screen on Android TV. Please see the video example.

So far, the solution I'm using is to create horizontal RecyclerView that updates when the user hits dpad right or left.

So in my adapter I have a method:

 public void incrementPosition() {
      if(currentSelection < getItemCount()) {
          previousSelection = currentSelection;
          notifyItemChanged(previousSelection);
          currentSelection++;
          notifyItemChanged(currentSelection);
      }
 }

Then when onBindViewHolder is called I have something like:

if(position == currentSelection) {
         //draw item to look like it's selected
     }
     else if(position == previousSelection) {
        // draw item to look it's NOT selected
     }

This will make the item appear to be selected, however the list doesn't scroll along with the new selection.

recentlyAddedRecyclerView.smoothScrollToPosition(currentSelection + 2)

(yes, I know currentSelection + 2 can go beyond the list, I have some if statements there)

The result is similar to the video posted above. However, it's not as "snappy" as I would like it to be. I just want to make sure this is the best way to implement it.

And this is a dynamic list from a network call. So I can't just make a layout with static views.

Bulat
  • 720
  • 7
  • 15
Marty Miller
  • 913
  • 2
  • 11
  • 27
  • Just confirming that you've seen this sample project/library: https://github.com/googlesamples/androidtv-Leanback and this one: https://github.com/googlesamples/leanback-showcase – Morrison Chang Dec 12 '16 at 20:01
  • Yes, I'm currently trying the leanback approach. These sample apps are great until you try to make an app that has a very specific ui. For example, I'm using a VerticalGridFragment to draw selectable images on the screen. Now how do I add pagination? How do I add a dropdown to the top of the layout when I didn't even inflate a layout to begin with? How do I add images to my sidebar when (again) there is no layout? – Marty Miller Dec 15 '16 at 19:10
  • I would think if you are doing pagination & dropdown menus you are doing something wrong or at least not geared toward a Leanback experience - and something not easily navigatable with a d-pad. Two resources to checkout: the Google IO video on the library: https://youtu.be/QFHIfQy8_Wc and Udacity Android TV course: https://www.udacity.com/course/android-tv-and-google-cast-development--ud875B – Morrison Chang Dec 16 '16 at 03:50
  • 1
    Thanks for the links. I watched the Youtube video. Things still seem very limiting. You can use styles to customize, but I didn't see anything about how to add other ui elements to your page of cards. I have to add a ViewPager to the top of my page. Btw, the dropdown is for selecting the season and the sort filter on the shows you are viewing. I don't think there is a way around that. – Marty Miller Dec 20 '16 at 18:37

1 Answers1

2

The v17.leanback.app libraries are the way to do it - that's what was used in your video. If you creates a fresh TV-only Android Studio Project with it's auto-generated Android Studio TV Activity it will give you a great starting point with tangible examples of header rows, customization, etc.

Just in case:

  1. Android Studio > File > New Project > name it & click Next
  2. Only select the TV Platform then click Next
  3. Select "Android TV Activity" then click Next

You'll care about the MainFragment & CardPresenter. Think of the BrowseFragment as a listview you populate with rows. Rows are filled with Cards which are built-upon FrameLayouts. RecyclerView is already integrated into leanback... I've found I have to spend a lot of time customizing them as you've noted, and just trying to find/navigate relevant online documentation. Good luck.

Bulat
  • 720
  • 7
  • 15
gfunk
  • 381
  • 1
  • 14
  • Have you actually used leanback to create a tv app that is similar to HBO Now or Netflix? My app looks nothing like a leanback demo. The sidebar needs icons, colors, and animations, the main screen has sort filters, buttons etc. How do you do this with leanback? I don't know understand how anyone could make a leanback application that looks like anything beyond the basic demo app. – Marty Miller Jun 16 '17 at 19:53
  • 1
    yes I have used leanback to create a tv app for such purposes, but yes it can be tricky. Take a look at the leanback showcase if you haven't: https://github.com/googlesamples/leanback-showcase (there is a video on youtube also). Beyond that I think you'd have to ask a more specific question than "What is the best way to make an Android TV menu?". Good luck hope things work out for you. p.s. I can't get your mp4 link to work. – gfunk Jun 18 '17 at 17:36