您的位置:首页 > 移动开发 > Android开发

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大。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: