Android动态布局的实现

方式一:

//注意需要先将view添加进父View,才能获取parmas
ll_point_group.addView(point);
  //设置间距(点放进线性布局中,和父布局保持一致,)
            LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(point.getLayoutParams());
            params.weight =dp2px(TitleActivity.this,7) ;
            params.height = dp2px(TitleActivity.this,7);
            if (i==0){
                point.setEnabled(true);//显示红色
            }else {
                point.setEnabled(false);//显示灰色
                params.leftMargin = dp2px(TitleActivity.this,8);
            }
//            point.setLayoutParams(params);
            ll_point_group.addView(point);

方式二:

        //    LinearLayout.LayoutParams params2 = new LinearLayout.LayoutParams(dp2px(TitleActivity.this,7), dp2px(TitleActivity.this,7));
           if (i==0){
                point.setEnabled(true);//显示红色
            }else {
                point.setEnabled(false);//显示灰色
                params.leftMargin = dp2px(TitleActivity.this,8);
            }
//            point.setLayoutParams(params2);
            ll_point_group.addView(point);

本质没有什么区别,都是构建view,然后将其加入到父布局中

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值