Layout _width ,Layout_height和heigh ,width 区别:

Layout,翻译为中文的意思是 布局,安排,版面设计。对于许多的组件的命令,都有Layout_x的区别,而许多的区别很明显,直接是Layout是相对于父容器(通常就是整个xml的布局)的改变,一个是相对于组件自己的改变。比较典型的就是gravity和layout_gravity,固然也有例外的 ,好比Layout_marginpandinghtml

对于每一个组件,能够独自的使用Layout _width ,layout_heigh直接的设置相对于父容器的大小,android

设置为 wrap_content或者 match_parent. 可是heigh ,width不能设置这样设置,不能设置相对于父容器,不然会产生布局

error: Error: String types not allowed (at 'width' with value 'wrap_content')。字体

而且,一个组件能够只有Layout _width ,layout_height。但却不能只有heigh ,width,而没有Layout _width ,layout_height,由于那样的组件会看不到。若是你要使用heigh ,width的话,就要先设置Layout _width ,layout_height,把heigh ,width用来做为组件的微调使用。spa

Xml:.net

[html] view plaincopyprint?翻译

  1. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"  设计

  2.     android:layout_width="match_parent"  orm

  3.     android:layout_height="match_parent"  xml

  4.     android:orientation="vertical" >  

  5.   

  6.     <Button  

  7.         android:layout_width="wrap_content"  

  8.         android:layout_height="wrap_content"  

  9.         android:text="hello talk"  

  10.         android:textColor="#482" />  

  11.   

  12.     <Button  

  13.         android:layout_width="wrap_content"  

  14.         android:layout_height="wrap_content"  

  15.         android:height="80dp"  

  16.         android:text="hello talk"  

  17.         android:textColor="#810"  

  18.         android:width="80dp" />  

  19.   

  20.     <TextView  

  21.         android:layout_width="wrap_content"  

  22.         android:layout_height="wrap_content"  

  23.         android:text="hello talk"  

  24.         android:textColor="#482" />  

  25.   

  26.     <TextView  

  27.         android:layout_width="wrap_content"  

  28.         android:layout_height="wrap_content"  

  29.         android:height="80dp"  

  30.         android:text="hello talk"  

  31.         android:textColor="#810"  

  32.         android:width="80dp" />  

  33.   

  34.     </LinearLayout>  


截图:

能够看出来不是改变的字体,而是直接改变的组件本生,但在TextvView中,好像效果不是很明显。

咱们知道,其实在设置宽高的时候,咱们是能够直接的把宽高设置为定制为:xdp,在这方面,Layout _width ,layout_height或者heigh ,width同样均可以设置。

至于还有其余的区别,有待发现中,呵呵!!


去网上找了下相关的,有这种说法:

若还要讲讲二者的区别的话,那就是:
android:width 的值,通常是 "100dp" 这样的数值;
android:layout_width 的值,通常是"fill_parent","wrap_content","match_parent".固然,它也能够像前者同样,设置数值的.

带"layout"的属性是指整个控件而言的,是与父控件之间的关系,如 layout_gravity 在父控件中的对齐方式, layout_margin 是级别相同的控件之间的间隙等等;

不带"layout" 的属性是指控件中文本的格式,如gravity是指文本的对齐方式等等,而其中文本的格式又受制约于它的控件在父控件中的属性. 


至于说layout的属性是针对文本的,在这个例子中没有获得很好证明,由于对文本设置了宽高为 80dp,但是也没啥效果啊。

相关文章
相关标签/搜索