android setLayoutParams不起作用

本文详细介绍了如何在Android中手动调整RadioButton的布局效果,通过设置LayoutParams来实现自定义的间距和大小,具体步骤包括创建LayoutParams对象、设置布局参数、添加RadioButton到RadioGroup,并最后调整布局效果。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

手动添加radiobutton,这样写无marginTop效果
RadioGroup.LayoutParams bt_params = new RadioGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ScreenUtil.dp2px(50,this));
bt_params.setMargins(0,ScreenUtil.dp2px(10,this),0,0);
radioButton.setLayoutParams(bt_params);
radioGroup.addView(radioButton);

把setLayoutParams()放到addView之后,就有效果
RadioGroup.LayoutParams bt_params = new RadioGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ScreenUtil.dp2px(50,this));
bt_params.setMargins(0,ScreenUtil.dp2px(10,this),0,0);
radioGroup.addView(radioButton);
radioButton.setLayoutParams(bt_params);
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值