当前位置:编程学习 > JAVA >>

Android RelativeLayout用纯java设置margin的办法

RelativeLayout rl =    new RelativeLayout(this);    
           
            MarginLayoutParams mp = new MarginLayoutParams(20,20);  //item的宽高
            mp.setMargins(0, 0, 25, 0);//分别是margin_top那四个属性
            RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(mp);
            lp.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
           
            Button bt = new Button(this);
            bt.setLayoutParams(lp);
           
            rl.addView(bt);


摘自 bingdongguke的专栏
补充:综合编程 , 其他综合 ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,