1.获取horizontalscrollview、radiogroup控件
//获取mRadioGroup horizontalscrollview布局
LayoutInflater inflater = (LayoutInflater)getSystemService(this.LAYOUT_INFLATER_SERVICE);
View view =inflater.inflate(R.layout.product_view, null);
mRadioGroup = (RadioGroup) view.findViewById(R.id.radio_group);
mHorizontalScrollView = (HorizontalScrollView) findViewById(R.id.horizontalscrollview);
2.设置控件参数
//parentItemArr为商品类别对象集合
for (int i =0;i<ParentItemArr.size();i++){
//添加radiobutton及设置参数(方便动态加载radiobutton)
RadioButton rb = new RadioButton(MainActivity.this);
//根据下标获取商品类别对象
Result itemArr = (Result) ParentItemArr.get(i);
rb.setText(itemArr.getName());
rb.setTextSize(13);
rb.setGravity(Gravity.CENTER);
//根据需要设置显示初始标签的个数,这里显示4个
rb.setLayoutParams(new ViewGroup.LayoutParams((int)(screenWidth/4.5), ViewGroup.LayoutParams.FILL_PARENT));
rb.setBackgroundResource(R.drawable.radiobutton_bg_selector);
//**原生radiobutton是有小圆点的,要去掉圆点而且最好按以下设置,设