宽度定义fill_parent等

本文详细介绍了Android布局中常用的三个视图尺寸属性:fill_parent、wrap_content和match_parent,解释了它们如何适应视图的水平或垂直大小,并提供了与Windows控件属性的对比。

来源:http://blog.sina.com.cn/s/blog_4ca9ceef0100zwc9.html

三个属性都用来适应视图的水平或垂直大小,一个以视图的内容或尺寸为基础的布局比精确地指定视图范围更加方便。


1)fill_parent
设置一个构件的布局为fill_parent将强制性地使构件扩展,以填充布局单元内尽可能多的空间。这跟Windows控件的dockstyle属性大体一致。设置一个顶部布局或控件为fill_parent将强制性让它布满整个屏幕。


2) wrap_content
设置一个视图的尺寸为wrap_content将强制性地使视图扩展以显示全部内容。以TextView和ImageView控件为例,设置为wrap_content将完整显示其内部的文本和图像。布局元素将根据内容更改大小。设置一个视图的尺寸为wrap_content大体等同于设置Windows控件的Autosize属性为True。


3)match_parent
   Android2.2中match_parent和fill_parent是一个意思 .两个参数意思一样,match_parent更贴切,于是从2.2开始两个词都可以用。那么如果考虑低版本的使用情况你就需要用fill_parent了



<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@drawable/beijing" tools:ignore="ExtraText"> <!-- 头像 --> <ImageView android:id="@+id/iv_avatar" android:layout_width="100dp" android:layout_height="100dp" android:layout_centerHorizontal="true" android:layout_marginTop="100dp" android:src="@drawable/touxiang" android:scaleType="centerCrop" /> <!-- 账号输入框 --> <TextView android:id="@+id/textView_user" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_below="@id/iv_avatar" android:layout_marginTop="20dp" android:layout_alignParentLeft="true" android:text="账号" android:textColor="#FFFFFF" android:textSize="20dp" tools:ignore="UnknownId" /> <!-- 密码输入框 --> <TextView android:id="@+id/textView_password" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_below="@id/textView_user" android:layout_marginTop="10dp" android:layout_alignParentLeft="true" android:text="密码" android:textColor="#FFFFFF" android:textSize="20dp" tools:ignore="UnknownId" /> <!-- 登录和注册按钮 --> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_below="@id/textView_password" android:layout_margin="16dp" android:orientation="horizontal" android:weightSum="2" tools:ignore="UnknownId"> <Button android:id="@+id/btn_login" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:text="登录" /> <Button android:id="@+id/btn_register" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:text="注册" /> </LinearLayout> <!-- 同意 QQ 服务协议文本 --> <TextView android:id="@+id/tv_agreement" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:layout_centerHorizontal="true" android:layout_marginBottom="16dp" android:text="同意 QQ 服务协议 " /> </RelativeLayout># 给账号密码添加文本框的具体步骤和操作
09-22
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值