<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);
是吗?
答案 0 :(得分: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