android多设备界面适配的利器:属性weight的妙用
2014-01-15 18:22
597 查看
1、按比例显示控件元素
属性weight的作用(不翻了,将就看吧):
if you give one view a weight of 2 and another one a weight of 1, the sum is 3, so the first view fills 2/3 of the remaining space and the second view fills the rest. If you add a third view and give it a weight of 1, then the first view (with weight of 2) now gets 1/2 the remaining space, while the remaining two each get 1/4.
EditText 占 2/3 , Button 占 1/3.
注意:只有当这两个控件的layout_width、layout_height都设置为"wrap_content"时,这个规则才能够成立。
2、一个控件独占,其它控件根据自身内容自动调整。
将需要独占的控件,其weight设置为1,同时宽度设置为0dp。根据自身内容调整的控件,不要设置weight。
效果:
<EditText android:id="@+id/edit_message" android:layout_weight="2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:hint="@string/edit_message" > <requestFocus /> </EditText> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:text="@string/button_send" />
属性weight的作用(不翻了,将就看吧):
if you give one view a weight of 2 and another one a weight of 1, the sum is 3, so the first view fills 2/3 of the remaining space and the second view fills the rest. If you add a third view and give it a weight of 1, then the first view (with weight of 2) now gets 1/2 the remaining space, while the remaining two each get 1/4.
EditText 占 2/3 , Button 占 1/3.
注意:只有当这两个控件的layout_width、layout_height都设置为"wrap_content"时,这个规则才能够成立。
2、一个控件独占,其它控件根据自身内容自动调整。
将需要独占的控件,其weight设置为1,同时宽度设置为0dp。根据自身内容调整的控件,不要设置weight。
效果:
相关文章推荐
- Android Studio适配利器——如何设置不同机型的预览界面
- Android中android:layout_weight属性解决不同机型平均分布的适配问题
- android多分辨率多密度下界面适配方案
- 当输入法调出时,如何让界面自动上移,使输入法不会遮挡到主界面 android:windowSoftInputMode属性使用
- 【Android 界面效果26】listview android:cacheColorHint,android:listSelector属性作用
- 移动设备界面开发: 专业Android, iPhone, iPad, Palm Pre设计工具箱
- android:layout_weight属性详解 (转)
- android:layout_weight属性详解
- 如何应用autosizing属性使iOS应用程序界面适配iPhone5
- Android中根据设备类型利用代码来动态控制某一界面的横竖屏显示
- android中如何在代码中直接设置View的layout_weight属性
- android多分辨率多密度下界面适配方案
- Android 对Layout_weight属性完全解析以及使用ListView来实现表格(自定义适配器)
- 详解Android中gravity和weight属性
- Android LinearLayout布局的layout_weight属性探究
- Android屏幕适配解析 - 详解像素,设备独立像素,归一化密度,精确密度及各种资源对应的尺寸密度分辨率适配问题
- Android布局中Layout_weight的属性
- 转android开发基础1Andriod界面设计适配和Android Studio中的资源
- android:layout_weight属性详解
- android weight属性