[size=x-large][i]android:layout_weight属性[/i][/size]
[b]layout_width="fill_parent"与layout_weight共同使用时[/b]
[b]button1占了4/10,button2占了6/10[/b]
[img]http://dl.iteye.com/upload/attachment/511228/88e8c2cb-e957-3661-8053-9131ab63142a.png[/img]
[b]layout_width="wrap_content"与layout_weight共同使用时[/b]
[b]效果与layout_width="fill_parent"时完全相反。button1的宽度占据了屏幕宽度的6/10,而button2的宽度占据了屏幕的4/10[/b]
[img]http://dl.iteye.com/upload/attachment/511230/c067ea17-88b3-36d9-8730-00a1ad9c8c8f.png[/img]
[b]layout_width="fill_parent"与layout_weight共同使用时[/b]
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<Button
android:id="@+id/button1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="6"
android:background="#F00"
android:text="button1" />
<Button
android:id="@+id/button2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="4"
android:background="#0F0"
android:text="button2" />
</LinearLayout>
[b]button1占了4/10,button2占了6/10[/b]
[img]http://dl.iteye.com/upload/attachment/511228/88e8c2cb-e957-3661-8053-9131ab63142a.png[/img]
[b]layout_width="wrap_content"与layout_weight共同使用时[/b]
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="6"
android:background="#F00"
android:text="button1" />
<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="4"
android:background="#0F0"
android:text="button2" />
</LinearLayout>
[b]效果与layout_width="fill_parent"时完全相反。button1的宽度占据了屏幕宽度的6/10,而button2的宽度占据了屏幕的4/10[/b]
[img]http://dl.iteye.com/upload/attachment/511230/c067ea17-88b3-36d9-8730-00a1ad9c8c8f.png[/img]