概述: android开发过程中我们会经常通过layout_weight来进行布局,这样做的好处就是可以多屏幕的适配。
LinearLayout中的layout_weight的使用在水平布局上和在垂直布局上都是一样的。所以我们就以水平布局上为例。
一、案例1
在水平布局上,显示两个View,我们知道如果不用weight属性的话,当我们把View1的weight设置为match_parent的时候,View2就会被挤到外面,从而看不到View2,。
那么我们为了 显示View2呢,就应用weight属性来满足我们的需求了。当View2 显示完整了,再把剩余的空间给View1,让View1,充满屏幕。
代码如下:
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<com.wubaiwan.wewin.widget.EditTextWithDel
android:id="@+id/edtVerificationCode"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:drawableLeft="@drawable/icon_password" >
</com.wubaiwan.wewin.widget.EditTextWithDel>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="30dp"
android:text="@string/action_get_veri_code" />
</LinearLayout>View1 充满屏幕,View2 包裹,这时候给View1加上更高的权重的话,那么就会得到我们想要的结果。
未完.......

本文介绍在Android开发中如何使用LinearLayout的layout_weight属性实现多屏幕适配。通过具体案例展示如何让两个视图组件在一个水平布局中和谐共存,其中一个视图充满屏幕而另一个则保持包裹内容的状态。
845

被折叠的 条评论
为什么被折叠?



