gpt4 book ai didi

android - 使用 PageRow 的 leanback BrowseFragment 的自定义 header

转载 作者:行者123 更新时间:2023-11-29 14:58:56 32 4
gpt4 key购买 nike

该代码由一个 BrowseFragment 组成,该 BrowseFragment 具有与每个标题行关联的多个列表行,引用此代码,我能够使用 PageRow 而不是 ListRow 正确实现它( https://github.com/googlesamples/leanback-showcase/blob/master/app/src/main/java/android/support/v17/leanback/supportleanbackshowcase/app/page/PageAndListRowFragment.java )

问题出在这个帮助我自定义标题的函数(向标题添加图标:

enter image description here

browseFragment.setHeaderPresenterSelector(new PresenterSelector() {
@Override
public IconHeaderPresenter getPresenter(Object item) {
return new IconHeaderPresenter();
}

});

添加后,标题不再被选中,我无法在它们之间导航。

这就是我创建浏览 fragment 的方式:

    ...     
browseFragment = new BrowseFragment();
browseFragment.setHeadersState(BrowseFragment.HEADERS_ENABLED);
browseFragment.prepareEntranceTransition();
browseFragment.setHeaderPresenterSelector(new PresenterSelector() {
@Override
public IconHeaderPresenter getPresenter(Object item) {
return new IconHeaderPresenter();
}

});

mBackgroundManager = BackgroundManager.getInstance(shared.main);
mBackgroundManager.attach(shared.main.getWindow());
browseFragment.getMainFragmentRegistry().registerFragment(IconPageRow.class,
new PageRowFragmentFactory(mBackgroundManager));

...

private static class PageRowFragmentFactory extends BrowseFragment.FragmentFactory {
private final BackgroundManager mBackgroundManager;

PageRowFragmentFactory(BackgroundManager backgroundManager) {
this.mBackgroundManager = backgroundManager;
}

@Override
public Fragment createFragment(Object rowObj) {
ArrayObjectAdapter adapter=((IconPageRow)rowObj).getAdapter();
RowsFragment rowsFragment = new RowsFragment();
rowsFragment.enableRowScaling(true);
rowsFragment.setAdapter(adapter);
mBackgroundManager.setDrawable(null);
rowsFragment.setOnItemViewClickedListener(browseClickListener);
rowsFragment.setOnItemViewSelectedListener(browseSelectedListener);
return rowsFragment;
}
}

最佳答案

解决方案是在 onCreateViewHolder 中向我的自定义 header 演示器 (IconHeaderPresenter) 添加以下两行:

view.setFocusable(true);
view.setFocusableInTouchMode(true);

关于android - 使用 PageRow 的 leanback BrowseFragment 的自定义 header ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52641014/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com