在leanback库中,我们可以在BrowseFragment中创建RowFragment,其中将包括动画并扩展视图。 这是BrowseFragment中的普通RowFragment:
以上项目来自here
我尝试在没有BrowseFragment的情况下仅在我的应用程序中实现Rows Fragment。我试图复制文件,但没有BrowseFragment,现在看起来像这样:
项目之间也没有空白。缩放后,第一个项目被裁剪。我试图在片段中添加填充,但裁剪得更多
这是我从项目中复制的主要代码:
public class PageRowFragment extends RowsSupportFragment {
private final ArrayObjectAdapter mRowsAdapter;
public PageRowFragment() {
mRowsAdapter = new ArrayObjectAdapter(new ShadowRowPresenterSelector());
setAdapter(mRowsAdapter);
setOnItemViewClickedListener(new OnItemViewClickedListener() {
@Override
public void onItemClicked(
Presenter.ViewHolder itemViewHolder,
Object item,
RowPresenter.ViewHolder rowViewHolder,
Row row) {
Toast.makeText(getActivity(), "Implement click handler", Toast.LENGTH_SHORT)
.show();
}
});
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
createRows();
// getMainFragmentAdapter().getFragmentHost().notifyDataReady(getMainFragmentAdapter());
}
private void createRows() {
String json = Util.inputStreamToString(getResources().openRawResource(
R.raw.page_row_example));
CardRow[] rows = new Gson().fromJson(json, CardRow[].class);
for (CardRow row : rows) {
if (row.getType() == CardRow.TYPE_DEFAULT) {
mRowsAdapter.add(createCardRow(row));
}
}
}
private Row createCardRow(CardRow cardRow) {
PresenterSelector presenterSelector = new CardPresenterSelector(getActivity());
ArrayObjectAdapter adapter = new ArrayObjectAdapter(presenterSelector);
for (Card card : cardRow.getCards()) {
adapter.add(card);
}
HeaderItem headerItem = new HeaderItem(cardRow.getTitle());
return new CardListRow(headerItem, adapter, cardRow);
}
}
我应该添加什么,以便布局与第二张图片相同? 谢谢!