Code example for GridView

Methods: setLayoutParamssetPaddingsetSelectorsetGravitysetHorizontalSpacingsetNumColumnssetStretchModesetVerticalSpacing, setOnItemClickListener

0
		super(context);
 
		mLayout = new LinearLayout(context);
		mLayout.setOrientation(LinearLayout.VERTICAL);
 
		gridView = new GridView(context);
		gridView.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT,
				LayoutParams.WRAP_CONTENT));
		gridView.setSelector(new ColorDrawable(Color.TRANSPARENT));// 选中的时候为透明色
		gridView.setNumColumns(bodyAdapter.resID.length);
		gridView.setStretchMode(GridView.STRETCH_COLUMN_WIDTH);
		gridView.setVerticalSpacing(0);
		gridView.setHorizontalSpacing(0);
		gridView.setPadding(0, 0, 0, 0);
		gridView.setGravity(Gravity.CENTER);
		gridView.setOnItemClickListener(bodyClick);
		//gridView.setBackgroundResource(R.drawable.button); 
		 
		mLayout.addView(gridView);
		// 设置默认项 
		this.setContentView(mLayout);