0
<LinearLayout
    android:id="@+id/LinearLayout1"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context=".MainActivity" >

如何在代码中编写上述 XML?

android.widget.LinearLayout.LayoutParams param = new LinearLayout.LayoutParams(
                LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT, 1);

那正确吗?

4

1 回答 1

2
//Create the layout params
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT);

//Create the LinearLayout
LinearLayout ll = new LinearLayout(context);
ll.setOrientation(LinearLayout.VERTICAL); //set orientation
ll.setLayoutParams(params); //asign your layout params
于 2013-03-05T23:08:33.173 回答