Android属性系列之layout_weight
2013-03-28 15:13
357 查看
对自己现在所了解的layout_weight属性进行记录,不求全面,只求正确!
layout_weight意为"权重",我的理解就是给组件设置一个显示大小的比例。
layout_weight设置一个值,会出现两种情况。
第一种:当组件的“layout_width”属性为“fill_parent”时,值越小,组件越大。
第二种:当组件的“layout_width”属性为“wrap_content”时,值越大,组件越大。
第一种情况:
Xml代码
<LinearLayout
android:layout_weight="1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
>
<Button
android:id="@+id/btn_save"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="保存"
/>
<Button
android:id="@+id/btn_return"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="4"
android:text="返回"
/>
</LinearLayout>
在这里"保存"按钮的Layout_weight=1,"返回"按钮的Layout_weight=4,layout_width="fill_parent"时, 运行效果为:
第二种情况:
Xml代码
<LinearLayout
android:layout_weight="1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
>
<Button
android:id="@+id/btn_save"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="保存"
/>
<Button
android:id="@+id/btn_return"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="4"
android:text="返回"
/>
</LinearLayout>
在这里"保存"按钮的Layout_weight=1,"返回"按钮的Layout_weight=4,layout_width="wrap_content"时,运行效果为:
以上为本人对已知情况的总结,如有不对或总结不足,望指教!
作者“背着行囊独自前行....”
layout_weight意为"权重",我的理解就是给组件设置一个显示大小的比例。
layout_weight设置一个值,会出现两种情况。
第一种:当组件的“layout_width”属性为“fill_parent”时,值越小,组件越大。
第二种:当组件的“layout_width”属性为“wrap_content”时,值越大,组件越大。
第一种情况:
Xml代码
<LinearLayout
android:layout_weight="1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
>
<Button
android:id="@+id/btn_save"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="保存"
/>
<Button
android:id="@+id/btn_return"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="4"
android:text="返回"
/>
</LinearLayout>
在这里"保存"按钮的Layout_weight=1,"返回"按钮的Layout_weight=4,layout_width="fill_parent"时, 运行效果为:
第二种情况:
Xml代码
<LinearLayout
android:layout_weight="1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
>
<Button
android:id="@+id/btn_save"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="保存"
/>
<Button
android:id="@+id/btn_return"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="4"
android:text="返回"
/>
</LinearLayout>
在这里"保存"按钮的Layout_weight=1,"返回"按钮的Layout_weight=4,layout_width="wrap_content"时,运行效果为:
以上为本人对已知情况的总结,如有不对或总结不足,望指教!
作者“背着行囊独自前行....”
相关文章推荐
- Android知识点剖析系列:深入了解layout_weight属性
- Android知识点剖析系列:深入了解layout_weight属性
- Android知识点剖析系列:深入了解layout_weight属性
- Android 对Layout_weight属性完全解析以及使用ListView来实现表格
- android:layout_weight属性详解
- Android中 android:layout_weight 属性 完美解释
- android:layout_weight 属性对于组件长度的影响
- android:layout_weight属性详解
- Android Layout_weight 属性
- 我的Android进阶之旅------>关于android:layout_weight属性的一个面试题
- 关于android:layout_weight属性使用注意事项
- Android视图控件属性layout_weight的作用
- Android系列之一:android:layout_weight和android:weightSum总结
- Android中layout_weight的属性理解
- Android中你也许不知道的线性布局Layout_weight属性权重比例分配原理
- android中如何在代码中直接设置View的layout_weight属性
- android:layout_weight属性的使用
- 50个Android开发技巧(1,使用android:layout_weight和android:weightSum属性的使用)
- android:layout_weight属性详解
- Android中 android:layout_weight 属性 完美解释