android:layout_weight属性详解
2011-08-19 09:20
691 查看
1. 在layout_width设置为fill_parent的时候,
layout_weight代表的是你的控件要优先尽可能的大,
但尽可能大是有限度的,即fill_parent.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal" android:layout_width="fill_parent"
android:layout_height="fill_parent">
<Button android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_weight="1"
android:text="Button1" />
<Button android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_weight="2"
android:text="Button2" />
</LinearLayout>
此时,Button1大,Button2小。
2. 在layout_width设置为wrap_content的时候,
layout_weight代表的是你的控件要优先尽可能的小,
但这个小是有限度的,即wrap_content.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal" android:layout_width="fill_parent"
android:layout_height="fill_parent">
<Button android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_weight="1"
android:text="Button1" />
<Button android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_weight="2"
android:text="Button2" />
</LinearLayout>
此时,Button1小,Button2大。
layout_weight代表的是你的控件要优先尽可能的大,
但尽可能大是有限度的,即fill_parent.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal" android:layout_width="fill_parent"
android:layout_height="fill_parent">
<Button android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_weight="1"
android:text="Button1" />
<Button android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_weight="2"
android:text="Button2" />
</LinearLayout>
此时,Button1大,Button2小。
2. 在layout_width设置为wrap_content的时候,
layout_weight代表的是你的控件要优先尽可能的小,
但这个小是有限度的,即wrap_content.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal" android:layout_width="fill_parent"
android:layout_height="fill_parent">
<Button android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_weight="1"
android:text="Button1" />
<Button android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_weight="2"
android:text="Button2" />
</LinearLayout>
此时,Button1小,Button2大。
相关文章推荐
- android:layout_weight属性详解
- android:layout_weight属性详解
- android:layout_weight属性详解
- android:layout_weight属性详解
- android:layout_weight属性详解(转)
- Android布局中的layout_weight和weightSum属性的详解及使用
- Android之layout_weight属性详解
- android:layout_weight属性详解
- android:layout_weight属性详解
- Android的layout_weight属性详解
- 详解 Android Views 元素的 layout_weight 属性
- 详解 Android Views 元素的 layout_weight 属性
- android:layout_weight属性详解 (转)
- android中布局文件中 layout_weight 的属性详解
- android:layout_weight 属性详解
- android:layout_weight属性详解
- Android中的layout_weight属性详解
- android:layout_weight属性详解
- android:layout_weight属性详解
- android:layout_weight属性详解