Android leanback 库 ListRowPresenter 整行展开
Posted
技术标签:
【中文标题】Android leanback 库 ListRowPresenter 整行展开【英文标题】:Android leanback library ListRowPresenter whole row expand 【发布时间】:2015-05-20 01:46:23 【问题描述】:我正在尝试在leanback library carousel中选择时使整行展开。
我想要的效果:
我正在处理 android TV 示例代码。
我试过setExpandedRowHeight(..);
和setRowHeight(..);
/**
* Created by sylversphere on 15-03-16.
*/
public class ExperimentalFragment extends BrowseFragment
private ArrayObjectAdapter mRowsAdapter;
private ExperimentalCardPresenter mCardPresenter;
private int NUM_ROWS = 20;
private int NUM_COLS = 40;
private Context context;
@Override
public void onActivityCreated(Bundle savedInstanceState)
super.onActivityCreated(savedInstanceState);
context = getActivity();
setTitle("Hello there you kid"); // Badge, when set, takes precedent
setHeadersState(HEADERS_DISABLED);
loadRows();
private void loadRows()
List<Movie> list = MovieList.setupMovies();
final ListRowPresenter lrp = new ListRowPresenter(FocusHighlight.ZOOM_FACTOR_LARGE);
lrp.setRowHeight(100);
lrp.setExpandedRowHeight(200);
mRowsAdapter = new ArrayObjectAdapter(lrp);
mCardPresenter = new ExperimentalCardPresenter();
int i;
for (i = 0; i < NUM_ROWS; i++)
ArrayObjectAdapter listRowAdapter = new ArrayObjectAdapter(mCardPresenter);
for (int j = 0; j < NUM_COLS; j++)
listRowAdapter.add(list.get(j % 5));
mRowsAdapter.add(new ListRow(listRowAdapter));
setAdapter(mRowsAdapter);
private void say(String s)
Toast.makeText(context, "Say : "+s, Toast.LENGTH_SHORT).show();
但行保持不变。我尝试手动为行设置动画,但现在行之间没有适当的填充。 如何使行扩展并保持填充?
【问题讨论】:
【参考方案1】:通过使用 setExpandedRowHeight,您只是在设置高度,而不是真正扩展行。当您希望通过调用setRowViewExpanded 方法扩展行视图时,您需要显式设置行视图扩展
public final void setRowViewExpanded (Presenter.ViewHolder holder, boolean expanded)
【讨论】:
选择行时不会展开。相反,它会在选择 gridview(菜单项的子项)时展开行。以上是关于Android leanback 库 ListRowPresenter 整行展开的主要内容,如果未能解决你的问题,请参考以下文章
Android leanback 库 ListRowPresenter 整行展开
Android Leanback 库 HorizontalGridView scrollToPosition 不起作用
如何使用 Leanback 库在 Android TV 中创建顶部导航栏