Code example for GridView

Methods: setAdaptersetGravitysetHorizontalSpacingsetNumColumnssetStretchModesetVerticalSpacing, setLayoutParams, setOnItemClickListener, setSelector

0
		super(context);
		 
		layout = new LinearLayout(context);
		layout.setOrientation(LinearLayout.VERTICAL);
		//标题选项栏 
		title = new GridView(context);
        title.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT)); 
        title.setNumColumns(titleAdapter.getCount());
		title.setStretchMode(GridView.STRETCH_COLUMN_WIDTH);
		title.setVerticalSpacing(1);
		title.setHorizontalSpacing(1);
		title.setGravity(Gravity.CENTER);
		title.setOnItemClickListener(titleClick);
		title.setAdapter(titleAdapter);
		title.setSelector(new ColorDrawable(Color.TRANSPARENT));//选中的时候为透明色
		this.titleAdapter=titleAdapter;
		//子选项栏 
		body = new GridView(context);
		body.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT));
		body.setSelector(new ColorDrawable(Color.TRANSPARENT));//选中的时候为透明色
		body.setNumColumns(4);