告诉我如何使用线性布局以编程方式为 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);
任何帮助将不胜感激
最佳答案
请引用以下链接将按钮添加到固定位置的相对布局。
Android User Interface Design: Relative Layout
也为此使用下面的代码。
Button but1 = new Button(this);
RelativeLayout.LayoutParams params2 = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
params2.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
but1.setLayoutParams(params2);
but1.setText("Press Here!");
// give the button an id that we know
but1.setId(1001);
layout1.addView(but1);
关于android - 以编程方式将位置分配给android中的按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11326384/