1.布局比重值 android:layout_weight
http://hi.baidu.com/mendynew/blog/item/5d0c5bee1bc4ceedb3fb953f.html
layout_weight的值是描述在布局完了之后,剩余空间如何分配。layout_weight相同只说明剩余空间的分配大小相同,而组件的实际宽度/高度则是组件需要的空间加上layout_weight分配的空间。layout_weight的设置和layout_height,layout_width不同的组合得出来不同的结果!
比如在LinearLayout中水平4个TextView,如果想既保持每个TextView的字符串长度不一致且每个TextView的宽度相同,把TextView中的属性android:layout_width值设置为fill_parent。
要想使每个控件按比例显示宽度,最好的方法还是配置或动态计算设置其layout_width值。
数值越小,比重占的越大,分配的越多。
在java代码中,它对应 LinearLayout.LayoutParams.weight;
LinearLayout.LayoutParams用于设置LinearLayout的子视图的布局参数。
2.gravity
举例button,
android:layout_gravity 表示按钮在父视图中的位置。
android:gravity表示button中的子视图(比如其文字)在button中的位置。
android:paddingLeft表示内部左边距
android:layout_marginLeft表示外部左边距
3.布局中必须设置 android:layout_width, android:layout_height
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
中必须设置 android:layout_width, android:layout_height属性,否则运行出错。
4.LinearLayout
获取其尺寸:先调用measure()方法测量,然后调用getMeasuredWidth()获取最小尺寸。
android3.0的LinearLayout有setShowDivider()方法设置分隔线或分隔图像;
当orientation="vertical"时,子view的layout_gravity只在水平方向起作用。
当orientation="hori..."时,子view的layout_gravity只在垂直方向起作用。
当设置LinearLayout的gravity为center时,可能子view会两个方向居中。
5.View存为图片
7.FrameLayout是最简单的一个布局对象。
它被定制为屏幕上的一个空白备用区域,之后可以在其中填充一个单一对象。所有的子元素将会固定在屏幕的左上角;不能为FrameLayout中的一个子元素指定一个位置。后一个子元素将会直接在前一个子元素之上进行覆盖填充,把它们部份或全部挡住(除非后一个子元素是透明的)。
9.TableLayout中没有行线和列线,只能自己添加View,并设置其宽高。
使用继承自View的类,在其draw方法中drawline.
http://www.microschool.net/Subjects/Blog/BlogArticle.aspx?id=11605
12.LayoutInflater
LayoutInflater把xml描述的layout布局转化为View对象
findViewById()找具体xml中的具体widget控件。
setContentView()一旦调用, layout就会立刻显示UI;inflate只会把Layout形成一个以view类实现成的对象,有需要时再用setContentView(view)显示出来
例:
View view=LayoutInflater.from(context).inflate(layoutId, null);
View inflate(int resource, ViewGroup root)
ViewGroup root可以是null,null时只创建一个resource对应的View,不是null时,会将创建的view自动加为root的child。
13.自定义View,以及layout属性
http://www.pin5i.com/showtopic-android-view-layout.html
实现把自定义的View在layout的xml文件中标签化显示:要重写CustomView(Context context, AttributeSet attrs)构造方法,注意在xml中加上包名。
获取视图在屏幕中的位置:view.getLocationOnScreen();
动态设置属性:layoutParams.addRule()可以实现动态设置所有属性。
14.可以使用merge标签来替代布局中的根标签FrameLayout
15.ScrollView
ScrollView中只能放置一个直接的子视图。
http://blog.51cto.com/zt/148
http://www.mikel.cn/%E5%BC%80%E5%8F%91%E7%AC%94%E8%AE%B0/%E8%BD%AC%E8%BD%BDandroid%E5%BC%80%E5%8F%91%E4%B9%8Bui%E5%BA%93%E5%8F%8A%E7%BB%84%E4%BB%B6%E8%B5%84%E6%BA%90.html