在Android布局文件中定义视图垂直或水平大小:
android:layout_width和android_layout_height的属性有fill_parent、wrap_content和match_parent
fill_parent、wrap_content和match_parent的区别:
1、wrap_content:表示大小刚好足够显示当前控件里的内容
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:text="传递数据" />

2、fill_parent和match_parent:
Android中fill_parent和match_parent(从Android2.2)是一样的。
为了兼容低版本,建议使用fill_parent
设置布局/控件为fill_parent将强制性让它布满整个屏幕或填满父控件的空白
<Button
android:id="@+id/button1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:text="传递数据" />

本文介绍了Android布局文件中视图的尺寸属性设置方法,包括fill_parent、wrap_content和match_parent的区别及应用场景。通过实例展示了如何设定按钮的宽度和高度。
129

被折叠的 条评论
为什么被折叠?



