android:layout_height fill_parent,如何区分Android wrap_content和fill_parent的详细说明

在Android中,总是把“wrap_content“或”fill_parent“组件属性”layout_width“和”layout_height“搞混?

看看下面的定义:

wrap_content–组件只想显示大到足以包围其内容只。

fill_parent–组件想要显示为大,填补剩余的空间。(后改名为match_parent在API级别8)

让我们看看下面的演示:

1。wrap_content

一个按钮元件,设置”wrap_content“在宽度和高度属性。它告诉Android显示按钮足够大,把它的内容”按钮ABC“只有。

"

android:layout_width="fill_parent"

android:layout_height="fill_parent" >

aeb012f4f213f37590c993461162fbab.png

image.png

2。fill_parent–宽度

改变“layout_width“”fill_parent“,按钮的宽度将填补剩余的空间,因为”一样大相对布局”按钮的高度,但仍足以把它的内容。

"

android:layout_width="fill_parent"

android:layout_height="fill_parent" >

f2f33469c4d5d922c5f09d404bf68b05.png

image.png

3.fill_parent–高度

改变“layout_height“”fill_parent“,按钮的高度将填补剩余的空间,因为”一样大相对布局”按钮的宽度,但仍足以把它的内容。

"

android:layout_width="fill_parent"

android:layout_height="fill_parent" >

93a6f769c2b066086919bc8f72fb48ab.png

image.png

4。fill_parent–宽度、高度

改变“layout_width“和”layout_height“”fill_parent”按钮将显示为整个设备的屏幕一样大,它只填满整个屏幕空间。

"

android:layout_width="fill_parent"

android:layout_height="fill_parent" >

92f93ae14006116e93a096cd3c8a5d02.png

image.png

原文博客地址:http://www.apkbus.com/blog-919651-76525.html

事实上,你可以指定一个确切的宽度和高度,但这是不推荐的,由于Android设备的各种屏幕尺寸。你只是不知道什么尺寸的Android设备上运行你的幻想中的应用。

<?xml version="1.0" encoding="utf-8"?> <TableLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/tableLayout1" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="@drawable/background"> <TableRow android:id="@+id/tableRow1" android:layout_width="wrap_content" android:layout_height="wrap_content"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:inputType="textEmailAddress" android:text="会员昵称:" android:height="50px" /> <EditText android:id="@+id/nickname" android:hint="请输入会员昵称" android:layout_width="300px" android:layout_height="wrap_content" android:singleLine="true" /> </TableRow> <TableRow android:id="@+id/tableRow2" android:layout_width="wrap_content" android:layout_height="wrap_content"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:inputType="textEmailAddress" android:text="输入密码:" android:height="50px" /> <EditText android:id="@+id/pwd" android:layout_width="300px" android:inputType="textPassword" android:layout_height="wrap_content" /> </TableRow> <TableRow android:id="@+id/tableRow3" android:layout_width="wrap_content" android:layout_height="wrap_content"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:inputType="textEmailAddress" android:text="确认密码:" android:height="50px" /> <EditText android:id="@+id/repwd" android:layout_width="300px" android:layout_height="wrap_content" android:inputType="textPassword" /> </TableRow> <TableRow android:id="@+id/tableRow4" android:layout_width="wrap_content" android:layout_height="wrap_content"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:inputType="textEmailAddress" android:text="E-mail:" android:height="50px" /> <EditText android:id="@+id/email" android:layout_width="300px" android:layout_height="wrap_content" android:inputType="textEmailAddress" /> </TableRow> <LinearLayout android:orientation="horizontal" android:layout_width="wrap_content" android:layout_height="wrap_content" > <Button android:text="注册" android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content"/> <Button android:text="重置" android:id="@+id/button2" android:layout_width="wrap_content" android:layout_height="wrap_content"/> </LinearLayout> </TableLayout>详细解释下这段代码的作用
06-13
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值