
//creating the relative layout relativeLayout relativeLayout = new relativeLayout(this); relativeLayout.LayoutParams rlp = new relativeLayout.LayoutParams( relativeLayout.LayoutParams.MATCH_PARENT,relativeLayout.LayoutParams.MATCH_PARENT); //creating buttons button button1 = new button(this); button1.setID(R.ID.button1); relativeLayout.LayoutParams params1 = new relativeLayout.LayoutParams( SCR_W/2,relativeLayout.LayoutParams.WRAP_CONTENT);//SCR_W is the device screenwIDth params1.addRule(relativeLayout.AliGN_PARENT_left); params1.addRule(relativeLayout.AliGN_PARENT_top); params1.setmargins(0,0); button1.setLayoutParams(params1); relativeLayout.addVIEw(button1); button button2 = new button(this); button2.setID(R.ID.button2); relativeLayout.LayoutParams params2 = new relativeLayout.LayoutParams( SCR_W/2,relativeLayout.LayoutParams.WRAP_CONTENT); params2.addRule(relativeLayout.AliGN_PARENT_left); params2.addRule(relativeLayout.BELOW,button1.getID()); params2.setmargins(0,0); button2.setLayoutParams(params2); relativeLayout.addVIEw(button2);//setting the relative layout as the contentvIEw setContentVIEw(relativeLayout,rlp);@H_403_12@提前致谢..
解决方法 我尝试了你的代码,对我有用,两个按钮位于距离0.要检查它,只需为每个按钮设置不同的颜色,您将看到它们在一起.
button1.setBackgroundcolor(color.BLUE);button2.setBackgroundcolor(color.RED);@H_403_12@ 总结以上是内存溢出为你收集整理的setmargin在android中的相对布局中不起作用全部内容,希望文章能够帮你解决setmargin在android中的相对布局中不起作用所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)