日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > Android >内容正文

Android

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

發(fā)布時間:2025/6/15 Android 24 豆豆
生活随笔 收集整理的這篇文章主要介紹了 如何区分Android wrap_content和fill_parent的详细说明 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

2019獨角獸企業(yè)重金招聘Python工程師標準>>>

在Android中,總是把“wrap_content“或”fill_parent“組件屬性”layout_width“和”layout_height“搞混?

看看下面的定義:

wrap_content–組件只想顯示大到足以包圍其內(nèi)容只。
fill_parent–組件想要顯示為大,填補剩余的空間。(后改名為match_parent在API級別8)
讓我們看看下面的演示:

1。wrap_content
一個按鈕元件,設置”wrap_content“在寬度和高度屬性。它告訴Android顯示按鈕足夠大,把它的內(nèi)容”按鈕ABC“只有。

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

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

</RelativeLayout>

image.png

2。fill_parent–寬度
改變“l(fā)ayout_width“”fill_parent“,按鈕的寬度將填補剩余的空間,因為”一樣大相對布局”按鈕的高度,但仍足以把它的內(nèi)容。

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

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

</RelativeLayout>

image.png

3.fill_parent–高度
改變“l(fā)ayout_height“”fill_parent“,按鈕的高度將填補剩余的空間,因為”一樣大相對布局”按鈕的寬度,但仍足以把它的內(nèi)容。

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

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

</RelativeLayout>

image.png

4。fill_parent–寬度、高度
改變“l(fā)ayout_width“和”layout_height“”fill_parent”按鈕將顯示為整個設備的屏幕一樣大,它只填滿整個屏幕空間。

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

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

</RelativeLayout>

image.png

原文博客地址:http://www.apkbus.com/blog-919651-76525.html
事實上,你可以指定一個確切的寬度和高度,但這是不推薦的,由于Android設備的各種屏幕尺寸。你只是不知道什么尺寸的Android設備上運行你的幻想中的應用。

轉(zhuǎn)載于:https://my.oschina.net/u/3724196/blog/1576217

總結(jié)

以上是生活随笔為你收集整理的如何区分Android wrap_content和fill_parent的详细说明的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。