声明
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:andro
android:
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:
android:orientation="vertical">
<TextView
android:
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"
android:textAppearance="?android:attr/textAppearanceMedium" />
<Button
android:
android:text="Click me Hide System statusbar"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<Switch
android:
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:track="@drawable/switch_track_light"
android:thumb="@drawable/switch_inner_light"
android:textOn="@string/empty"
android:textOff="@string/empty1"/>
</LinearLayout>
</FrameLayout>
java文件onCreate中设置LinearLayout的width和height
mLinearLayout = (LinearLayout) findViewById(.linear_layout);
//方法1:
(
new (400, 200));
方法1会报下面的异常
01-03 01:48:12.914: E/AndroidRuntime(3353): FATAL EXCEPTION: main
01-03 01:48:12.914: E/AndroidRuntime(3353): : $LayoutParams cannot be cast to $LayoutParams
//方法2: 可以正确使用
lp;
lp= ();
=400;
=200;
(lp);