笔记:读Android文档的一些细节1

来源:互联网 发布:p图卖萌软件 编辑:程序博客网 时间:2024/06/06 06:41

The default weight for all views is 0, so if you specify any weight value greater than 0 to only one view, then that view fills whatever space remains after all views are given the space they require. So, to fill the remaining space in your layout with the EditText element, give it a weight of 1 and leave the button with no weight.

    <EditText        android:layout_weight="1"        ... />

In order to improve the layout efficiency when you specify the weight, you should change the width of theEditText to be zero (0dp). Setting the width to zero improves layout performance because using "wrap_content"as the width requires the system to calculate a width that is ultimately irrelevant because the weight value requires another width calculation to fill the remaining space.

    <EditText        android:layout_weight="1"        android:layout_width="0dp"        ... />

Figure 3 shows the result when you assign all weight to the EditText element.

Figure 3. The EditText widget is given all the layout weight, so fills the remaining space in the LinearLayout.

 

0 0
原创粉丝点击