View与ViewGroup

来源:互联网 发布:怎样在淘宝上卖东西 编辑:程序博客网 时间:2024/06/05 05:23

继承层次(ViewGroup继承View)

java.lang.Object   ↳android.view.View

   ↳android.view.ViewGroup

布局层次:(树结构)



View与ViewGroup的定义

   View:可以在屏幕上绘制可以和用户进行交互视图
   ViewGroup:持有View或者ViewGroup   定义了布局的界面

View的基本属性

android:layout_width="match_parent"  控件的宽
android:layout_height="match_parent" 控件的高
match_parent:匹配父控件  如果没有父控件  匹配手机的宽和高 
fill_parent:和match_parent 一样   2.3以前使用
wrap_content:内容包裹   wrap_content指控件的大小正好包裹住内容
                       可以用固定的宽度或者高度
                             设置单位:控件的大小用dp 设备独立像素  和硬件有关   dpi(手机屏幕宽的平方 +手机高的平方)开根号  ÷ 手机尺寸
                                           文字设置大小sp
android:background="#ff0000"         背景颜色
android:id="@+id/tv"   控件的id(标识)  会在gen文件自动生成  R文件  
padding:内边距   里面内容距离控件的边缘的距离
android:paddingLeft="10dp"   左
android:paddingTop="20dp"       上
android:paddingRight="30dp"     右
android:paddingBottom="40dp"    下    
android:padding="10dp"  包含上下左右  确保四个边的边距一致  才使用padding
margin  外边距
android:layout_marginLeft="10dp"  左
android:layout_marginTop="20dp"     上
android:layout_marginRight="30dp"   右
android:layout_marginBottom="40dp"  下
android:layout_margin="10dp"   包含上下左右   确保四个边的边距一致 layout_margin
   


0 0