Android Wrap_content And Fill_parent Example
来源:互联网 发布:淘宝里在哪里查看评价 编辑:程序博客网 时间:2024/06/10 23:17
Android Wrap_content And Fill_parent Example
在 Android 中,经常对组件属性 “layout_width” 和“layout_height“ 使用 “wrap_content” 或 “fill_parent” ,那么,“wrap_content” 与“fill_parent” 的区别是什么呢?
看下面的定义 :
fill_parent – The component want to display as big as its parent, and fill in the remaining spaces. (renamed match_parent in API Level 8)
上面的定义太罗嗦了,还是看例子吧:
1. wrap_content
将Button按钮组件的 width 和 height 属性的值设置为“wrap_content”。It tell Android to display the button big enough to enclose it’s content “Button ABC” only.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="fill_parent" android:layout_height="fill_parent" tools:context=".MainActivity" > <Button android:id="@+id/btnButton1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Button ABC" /></RelativeLayout>
2. fill_parent – width
Change the “layout_width” to “fill_parent“, now, the button’s width will fill in the remaining spaces, just as big as it’s parent “RelativeLayout“, but button’s height is still big enough to enclose it’s content only.
将 “layout_width”的值改为“fill_parent“,现在呢,查看结果,button按钮的宽度已经变了,button按钮 填充剩余空白,正如它的父级RelativeLayout,
但是,button按钮的高度没有改变,仍然是按钮尽可能大的包裹它的文本内容。
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="fill_parent" android:layout_height="fill_parent" tools:context=".MainActivity" > <Button android:id="@+id/btnButton1" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="Button ABC" /></RelativeLayout>
3. fill_parent – height
Change the “layout_height” to “fill_parent“, now, the button’s height will fill in the remaining spaces, just as big as it’s parent “RelativeLayout“, but button’s width is still big enough to enclose it’s content only.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="fill_parent" android:layout_height="fill_parent" tools:context=".MainActivity" > <Button android:id="@+id/btnButton1" android:layout_width="wrap_content" android:layout_height="fill_parent" android:text="Button ABC" /></RelativeLayout>
4. fill_parent – width, height
Change the both “layout_width” and “layout_height” to “fill_parent“, the button will display as big as the whole device screen, it just fill in the entire screen space.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="fill_parent" android:layout_height="fill_parent" tools:context=".MainActivity" > <Button android:id="@+id/btnButton1" android:layout_width="fill_parent" android:layout_height="fill_parent" android:text="Button ABC" /></RelativeLayout>
参考文献:
http://www.mkyong.com/android/android-wrap_content-and-fill_parent-example/
=============================
再看一个例子,就能理解 “wrap包裹”的意思了:
button.setText("hello"+"\n"+"beijing"+"\n"+"android");
- Android Wrap_content And Fill_parent Example
- Android:wrap_content fill_parent match_parent
- Android fill_parent和wrap_content分析
- Android fill_parent和wrap_content分析
- Android fill_parent和wrap_content分析
- Android fill_parent和wrap_content分析
- Android fill_parent和wrap_content分析
- Android fill_parent、wrap_content的区别
- Android fill_parent和wrap_content分析
- Android fill_parent和wrap_content分析
- Android fill_parent和wrap_content分析
- Android中的fill_parent、match_parent、wrap_content
- Android fill_parent、wrap_content和match_parent
- Android fill_parent和wrap_content理解
- Android fill_parent和wrap_content分析
- Android之fill_parent和wrap_content
- Android fill_parent和wrap_content分析
- Android的fill_parent和wrap_content
- WebStorm 6.0 代码提示配置
- Android中常用动画效果
- redis笔记--初识redis
- Win7(64bit) + VS2010 +Opencv 2.4.4 配置
- Android Interface Definition Language (AIDL) android接口定义语言 开发文档翻译 - 1
- Android Wrap_content And Fill_parent Example
- zoj 3717 2-SAT
- poj3273
- oracle emp表不见了怎么办
- 《算法竞赛-训练指南》第一章-1.4_LA 3708
- 零散笔记
- 重新安装mysql,发生错误怎么处理
- spring 3.x 企业应用开发实战 PDF 陈雄华 完整版 路径
- SQL Server 触发器