如何区分Android wrap_content和fill_parent的详细说明

发布时间:2019-06-13 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了如何区分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“只有。

<?XMl version="1.0" encoding="utf-8"?>
<RelativeLayout >"http://schemas.android.COM/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

    <Button
        android:id="@+id/BTnButton1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Button ABC"/>

</RelativeLayout>

如何区分Android wrap_content和fill_parent的详细说明

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

<?xML version="1.0" encoding="utf-8"?>
<RelativeLayout >"http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

    <Button
        android:id="@+id/btnButton1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="Button ABC"/>

</RelativeLayout>

如何区分Android wrap_content和fill_parent的详细说明

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

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout >"http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

    <Button
        android:id="@+id/btnButton1"
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        android:text="Button ABC"/>

</RelativeLayout>

如何区分Android wrap_content和fill_parent的详细说明

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

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout >"http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

    <Button
        android:id="@+id/btnButton1"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:text="Button ABC"/>

</RelativeLayout>

如何区分Android wrap_content和fill_parent的详细说明

原文博客地址:http://www.apkbus.com/blog-91...

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

脚本宝典总结

以上是脚本宝典为你收集整理的如何区分Android wrap_content和fill_parent的详细说明全部内容,希望文章能够帮你解决如何区分Android wrap_content和fill_parent的详细说明所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。