Leanback for Android TV : Unsetting Video Title Increases Spacing between Rows

怎甘沉沦 提交于 2019-12-05 18:35:57

Without those two rows of text, the playback controls are now at the top of that view. You can probably apply margins or padding to the playback controls to shift it to the expected location.

Turns out the playback controls need some view above it so they don't occupy the top of their container view (@Nick is right). But I wanted to share my solution in case anyone has a similar need.

PlaybackControlsRowPresenter can take in any presenter in its constructor, not just AbstractDetailsDescriptionPresenters. So createControlsRowAndPresenter() should look like this:

EmojiRowPresenter emojiRowPresenter = new EmojiRowPresenter() {
            @Override
            protected void onBindEmojiInfo(EmojiRowView rowView, EmojiInfo emojiInfo) {
                rowView.setEmojiInfo(emojiInfo);
            }
        };
PlaybackControlsRowPresenter presenter = new PlaybackControlsRowPresenter(emojiRowPresenter) { // replace the default description presenter with custom presenter
... 
}

// everything else stays as before

and EmojiRowPresenter is a subclass of Presenter that looks like this:

public abstract class EmojiRowPresenter extends Presenter {
    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent) {
        EmojiRowView emojiRowView = new EmojiRowView(parent.getContext());
        emojiRowView.setFocusable(true);
        emojiRowView.setFocusableInTouchMode(true);
        return new ViewHolder(emojiRowView);
    }

    @Override
    public void onBindViewHolder(Presenter.ViewHolder viewHolder, Object item) {
        EmojiRowView emojiRowView = (EmojiRowView) viewHolder.view;
        PlaybackControlHelper glue = (PlaybackControlHelper) item;
        EmojiInfo emojiInfo = glue.getEmojiInfo();
        if (emojiInfo != null) {
            onBindEmojiInfo(emojiRowView, emojiInfo);
        }
    }

    @Override
    public void onUnbindViewHolder(Presenter.ViewHolder viewHolder) {
        // ...
    }

    protected abstract void onBindEmojiInfo(EmojiRowView rowView, EmojiInfo emojiInfo);
}

Of course, EmojiRowView creates the view from the layout that defines each item. Here's the end result:

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!