我在TableLayout中动态创建一个TableRow并向其添加一个按钮,但它没有将宽度设置为我指定的宽度。我做错了什么?
public View onCreateView(LayoutInflater inflater, ViewGroup parent, Bundle savedInstanceState){
View v = inflater.inflate(R.layout.fragment_hello_moon, parent, false);
Button myButton = new Button(getActivity());
myButton.setText("Push Me");
myButton.setWidth(3);
myButton.setId(12);
TableLayout tl = (TableLayout)v.findViewById(R.id.l1);
TableRow tr = new TableRow(getActivity());
tr.addView(myButton);
tl.addView(tr);
return v;
}