android多设备界面适配的利器:属性weight的妙用
16lz
2021-12-04
1、按比例显示控件元素
<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(安卓)控件布局常用属性
- Android(安卓)控件布局常用属性
- Android属性
- Android(安卓)控件相关
- Android学习第一章第一节android学习路线图
- ANDROID 控件常用属性
- AndroidUI组件之ListView小技巧
- AndroidUI组件之ListView小技巧
- Android设置窗口、控件透明度