设置宽度不起作用Android

时间:2013-10-19 16:58:31

标签: android

我在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;

}

0 个答案:

没有答案