大家好,又见面了,我是你们的朋友全栈君。
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)
发布者:全栈程序员-用户IM,转载请注明出处:https://javaforall.cn/159863.html原文链接:https://javaforall.cn
【正版授权,激活自己账号】: Jetbrains全家桶Ide使用,1年售后保障,每天仅需1毛
【官方授权 正版激活】: 官方授权 正版激活 支持Jetbrains家族下所有IDE 使用个人JB账号...