android:layout_width与android:width的区别
来源:互联网 发布:我的阿里云tv工程模式 编辑:程序博客网 时间:2024/04/29 17:02
最近正在自学安卓开发,先是学习界面编程,在学习当中看到书上TextView控件有android:layout_width属性与android:width属性,一下搞不明白,所以写了个Demo测试,以下是xml文件
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" tools:context=".MainActivity"> <TextView android:id="@+id/view1" android:layout_width="40dp" android:layout_height="wrap_content" android:background="#0f0" android:width="300dp" android:text="helloworld" /> <TextView android:id="@+id/view2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="#f00" android:width="300dp" android:text="helloworld" /> <TextView android:id="@+id/view3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="#00f" android:width="30dp" android:text="helloworld" /> <TextView android:id="@+id/view4" android:layout_width="fill_parent" android:layout_height="wrap_content" android:background="#90f" android:width="30dp" android:text="helloworld" /> <TextView android:id="@+id/view5" android:layout_width="150dp" android:layout_height="wrap_content" android:background="#28f" android:width="30dp" android:text="helloworld" /></LinearLayout>
运行结果如下所示:
根据以上运行结果得出以下结论:
1.layout_width主要是相对父控件而言设置的宽度,可以为wrap_content,fill_parent以及具体的宽度。而width是对于自身而言设置的宽度,一般赋值都是具体的宽度。
2.当layout_width为wrap_content时,控件真实的宽度由width决定;当layout_width为fill_parent或具体某个宽度时,控件真实宽度由layout_width决定
1.layout_width主要是相对父控件而言设置的宽度,可以为wrap_content,fill_parent以及具体的宽度。而width是对于自身而言设置的宽度,一般赋值都是具体的宽度。
2.当layout_width为wrap_content时,控件真实的宽度由width决定;当layout_width为fill_parent或具体某个宽度时,控件真实宽度由layout_width决定
本人是初学者,如有错误,敬请指正,谢谢!
1 0
- android:layout_width与android:width的区别
- android:layout_width和android:width的区别
- android 布局中layout_width与width的区别
- Android中的width(height)与layout_width(layout_height)的区别
- Android中的layout_width和width的区别
- Android中的layout_width和width的区别
- Android中android:layout_width与 android:width有什么区别?
- XML布局文件中 android:width与android:layout_width 的区别
- Android里Layout_width和width的使用区别
- Android的android:width和android:layout_width
- android:layout_width与android:with的区别
- Android中的android:layout_width和android:width区别
- Android中的android:layout_width和android:width区别
- layout_width和width的区别
- layout_width和width的区别
- width与layout_width,height与layout_height的区别
- Android的XML布局文件中layout_width和width的区别
- 解释android:Layout_width 和Android:width的区别还有android:Layout_gravity和android:gravity的区别和用法
- mysql备份还原(视图、存储过程)
- OC中的内存管理
- virtualbox下ubuntu共享文件夹自动挂载
- 【jQuery】Ajax函数:$.get(),$.post(),$.ajax(),$.getJSON()
- maven项目中自动下载jar包的pom.xml配置
- android:layout_width与android:width的区别
- LeetCode 102 : Binary Tree Level Order Traversal(Java)
- NStimer(计时器)实现按钮的发送验证码的一个小demo
- 新手学EasyUI(八)----SubGrid三级嵌套
- 自适应增益AGC算法
- 王学岗的属性动画上(二)——objectAnimator的非主流用法
- 求教,CSS3绚丽照片墙JS代码及其中遇到的问题
- 物联网与嵌入式系统概论-week3- Hardware and Software-Lesson1: Hardware Components
- 用ajax获取json数据并在网页上面显示小例子