【发布时间】:2012-07-04 19:09:26
【问题描述】:
告诉我如何使用线性布局以编程方式将位置分配给 android 中的按钮。默认情况下,它占据屏幕的极左位置。我也想使用线性布局来做到这一点,请不要建议我使用相对布局。以下是我的代码
buttons_and_edittext=new LinearLayout(HelloAugmentedWorldActivity.this);
buttons_and_edittext = (LinearLayout)findViewById(R.id.linearLayout1);
buttons_and_edittextParameters = new LinearLayout.LayoutParams(120, 150);
button3 = new Button(this);
button3.setText("log");
buttons_and_edittext.addView(button3,
buttons_and_edittextParameters);
任何帮助将不胜感激,谢谢
【问题讨论】:
-
非常感谢。我只需要使用buttons_and_edittextParameters.setMargins(30, 20, 30, 0);
-
因为你建议我一个网站,我可以得到关于使用相对布局的好教程,我总结了使用相对布局感到不舒服的地方,因为我是 android 新手。
-
@user1278731 请看我的回答。