【发布时间】:2016-09-14 07:58:15
【问题描述】:
我是 android 编程新手。
我只是发现 xml 并不是设置布局的唯一方法。所以,我试图理解以编程方式设置的布局。我一直在尝试改变按钮的位置。如何设置布局重力,以便按钮位于预期的轴上,比如说bottom 和center?
顺便说一句,icicle 和 savedInstanceState 是一样的吗?
这是我偶然发现的编码。 你能告诉我设置重力的正确方法吗?
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
LinearLayout one = new LinearLayout(this);
myButton1 = new Button1(this);
one.addView(myButton1,
new LinearLayout.LayoutParams(
ViewGroup.LayoutParams.WRAP_CONTENT,
ViewGroup.LayoutParams.WRAP_CONTENT,
0));
myButton2 = new Button2(this);
one.addView(mButton2,
new LinearLayout.LayoutParams(
ViewGroup.LayoutParams.WRAP_CONTENT,
ViewGroup.LayoutParams.WRAP_CONTENT,
0));
setContentView(one);
【问题讨论】:
标签: android android-layout android-studio gravity layoutparams