【发布时间】:2015-01-09 19:52:21
【问题描述】:
我正在尝试制作一个 100x100 像素的按钮并将其添加到位置 3,3 的网格布局中
Button btn = new Button(this);
btn.setLayoutParams(new ViewGroup.LayoutParams(100,100));
GridLayout grid4x4 = (GridLayout)findViewById(R.id.grid4x4);
//I've narrowed it down to the conclusion that this line is the problem:
grid4x4.addView(btn,new GridLayout.LayoutParams(GridLayout.spec(3),GridLayout.spec(3)));
//if i just use:
//grid4x4.addView(btn); I get the button the size I want it, but I need it to be on
//the 3,3 position of the grid.
这个“几乎”有效,除了添加的按钮大于 100x100 像素这一事实,正如您所见,我正在尝试修复我想要的尺寸,但由于某种原因这不是我得到的尺寸。
【问题讨论】:
标签: android button android-studio size layoutparams