1.android:layout-weight 这个属性允许我们使用比例的方式来指定控件的大小,它在手机屏幕的适应性方面可以起到一个非常重要的作用。
将android:layout-weight属性的值设置为1就会平分屏幕宽度。原理如下,系统会先将所有layout下所有控件指定的:layout-weight值相加,最后再平均分配
此种方式适用于水平方向的控件布局
<EditText
android:id="@+id/input_message"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:hint="type something" />
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:id="@+id/send"
android:text="send"/>
2.如果只是设置其中一个的 android:layout_weight的值为1,剩下另一个设置为适应内容大小,那么设置的将占据剩余屏幕宽度,例子如下:
<?xml version="1.0" encoding="utf-8"?><EditText
android:id="@+id/input_message"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:hint="type something" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/send"
android:text="send"/>
介绍了android:layout-weight属性在手机屏幕适应性方面的重要作用。将该属性值设为1可平分屏幕宽度,系统先将所有控件的layout-weight值相加再平均分配,适用于水平方向控件布局。还提及设置一个为1,另一个适应内容大小时的布局情况。
958

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



