如何区分Android wrap_content和fill_parent的详细说明
2019獨角獸企業重金招聘Python工程師標準>>>
在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 xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
</RelativeLayout>
image.png
2。fill_parent–寬度
改變“layout_width“”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" >
</RelativeLayout>
image.png
3.fill_parent–高度
改變“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" >
</RelativeLayout>
image.png
4。fill_parent–寬度、高度
改變“layout_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" >
</RelativeLayout>
image.png
原文博客地址:http://www.apkbus.com/blog-919651-76525.html
事實上,你可以指定一個確切的寬度和高度,但這是不推薦的,由于Android設備的各種屏幕尺寸。你只是不知道什么尺寸的Android設備上運行你的幻想中的應用。
轉載于:https://my.oschina.net/u/3724196/blog/1576217
總結
以上是生活随笔為你收集整理的如何区分Android wrap_content和fill_parent的详细说明的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: django 内置 admin
- 下一篇: 前端圈的寒冬要来?