我们申明Layout有2中方式:
1.Declare UI elements in XML
2.Instantiate layout elements at runtime
直接用xml申明的布局文件可以很好的将程序logic跟程序界面元素分开,每一个
layout文件都必须包含一个root element(View or ViewGroup),当然每一个View
or ViewGroup都有自己相应的View属性设置.
每一个View都可能需要设置一个自己的id:
android:id="@+id/my_button"
symbol (+) means that this is a new resource name that must be created
and added to our resources (in the R.java file)
When referencing an Android resource ID, 我们不需要添加+,但必须添加android
包命名空间like so:android:id="@android:id/empty"
在xml中定义组件元素的时候,都必须有(layout_width and layout_height)属性,
Many LayoutParams also include optional margins and borders
"wrap_content":自适应显示内容的尺寸
"fill_parent" (match_parent in API Level 8)填满父View显示区域
一个View有2中宽,高度
1.The first pair is known as measured width and measured height.
These dimensions define how big a view wants to be within its parent
2.The second pair is simply known as width and height
These dimensions define the actual size of the view on screen
里面内容有些怕自己翻译不准确,所以就直接贴上了
1.Declare UI elements in XML
2.Instantiate layout elements at runtime
直接用xml申明的布局文件可以很好的将程序logic跟程序界面元素分开,每一个
layout文件都必须包含一个root element(View or ViewGroup),当然每一个View
or ViewGroup都有自己相应的View属性设置.
每一个View都可能需要设置一个自己的id:
android:id="@+id/my_button"
symbol (+) means that this is a new resource name that must be created
and added to our resources (in the R.java file)
When referencing an Android resource ID, 我们不需要添加+,但必须添加android
包命名空间like so:android:id="@android:id/empty"
在xml中定义组件元素的时候,都必须有(layout_width and layout_height)属性,
Many LayoutParams also include optional margins and borders
"wrap_content":自适应显示内容的尺寸
"fill_parent" (match_parent in API Level 8)填满父View显示区域
一个View有2中宽,高度
1.The first pair is known as measured width and measured height.
These dimensions define how big a view wants to be within its parent
2.The second pair is simply known as width and height
These dimensions define the actual size of the view on screen
里面内容有些怕自己翻译不准确,所以就直接贴上了