?
public class HomeFragment extends BrowseSupportFragment {
private static final int GRID_ITEM_WIDTH = 200;
private static final int GRID_ITEM_HEIGHT = 200;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// setHeadersState(HEADERS_DISABLED);
String[] headerItem = new String[] {"P1", "P2", "P3", "P5", "P6", "P7", "P8", "P9"};
int coverItemCount = 20;
ArrayObjectAdapter rowsAdapter = new ArrayObjectAdapter(new ListRowPresenter());
for (String item : headerItem) {
HeaderItem gridHeader = new HeaderItem( item);
GridItemPresenter mGridPresenter = new GridItemPresenter();
ArrayObjectAdapter gridRowAdapter = new ArrayObjectAdapter(mGridPresenter);
int idx = 0;
while (idx < coverItemCount) {
String title = item + "-" + idx;
gridRowAdapter.add(title);
idx = idx + 1;
}
rowsAdapter.add(new ListRow(gridHeader, gridRowAdapter));
}
setAdapter(rowsAdapter);
}
private class GridItemPresenter extends Presenter {
@Override
public ViewHolder onCreateViewHolder(ViewGroup parent) {
TextView view = new TextView(parent.getContext());
view.setLayoutParams(new ViewGroup.LayoutParams(GRID_ITEM_WIDTH, GRID_ITEM_HEIGHT));
view.setFocusable(true);
view.setFocusableInTouchMode(true);
view.setBackgroundColor(
ContextCompat.getColor(getActivity(), android.R.color.holo_red_light));
view.setTextColor(Color.WHITE);
view.setGravity(Gravity.CENTER);
return new ViewHolder(view);
}
@Override
public void onBindViewHolder(ViewHolder viewHolder, Object item) {
((TextView) viewHolder.view).setText((String) item);
}
@Override
public void onUnbindViewHolder(ViewHolder viewHolder) {
}
}
}
?最近开箱看了看 Android TV 的开发,发现和手机开发区别不大,主要页面构成变成类似 ViewPage(由 BrowseSupportFragment.setAdapter?管理,以每行为单位显示,GridItemPresenter 可以理解为每行的 Adapter)
|