【android】RadioGroup+RadioButton+HorizontalScrollview实现顶部横向菜单栏

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是有小圆点的,要去掉圆点而且最好按以下设置,设
评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值