android:weight属性能够根据手机高宽按设定比例显示控件

如:

宽度上按比例显示

<LinearLayout
android:layout_marginTop="5dp"
androidrientation="horizontal"
android:layout_width="fill_parent"----------------让其满宽
android:layout_height="wrap_content">
<Button
android:id="@+id/first_sex1_4"
android:layout_marginLeft="15dp"
android:layout_width="0dp"---------设置0dp,让宽度由比例生成
android:layout_weight="1"
android:layout_height="50dp"/>
<Button
android:id="@+id/first_sex1_5"
android:layout_marginLeft="5dp"
android:layout_width="0dp"
android:layout_weight="3"
android:layout_height="50dp"/>
</LinearLayout>

注意现在android:layout_width="0dp"

最终3个按钮显示的宽度比例为1:3,和weight一样,值大的权高,显示宽度大


然而如果把android:layout_width="fill_parent"

<LinearLayout
android:layout_marginTop="5dp"
androidrientation="horizontal"
android:layout_width="fill_parent"----------------让其满宽
android:layout_height="wrap_content">
<Button
android:id="@+id/first_sex1_4"
android:layout_marginLeft="15dp"
android:layout_width="fill_parent"---------设置fill_parent,让宽度由比例生成
android:layout_weight="1"
android:layout_height="50dp"/>
<Button
android:id="@+id/first_sex1_5"
android:layout_marginLeft="5dp"
android:layout_width="fill_parent"
android:layout_weight="3"
android:layout_height="50dp"/>
</LinearLayout>

注意现在android:layout_width="fill_parent"

最终3个按钮显示的宽度比例为3:1,和weight相反,值大的权低,显示宽度小


更多相关文章

  1. Android官方入门文档[6]添加Action按钮
  2. 界面编程之基本界面组件(5)ToggleButton(状态开关按钮)
  3. android Button 切换背景,实现动态按钮和按钮颜色渐变
  4. android点击按钮控制图片切换-kotlin
  5. 选择框在右边的单选按钮。。
  6. android : 圆角按钮 shape属性
  7. 使用多状态按钮ToggleButton
  8. Android如何避免输入法弹出时遮挡住按钮或输入框

随机推荐

  1. Android(安卓)UI开发
  2. Android: Android中各种onTouch事件
  3. Android(安卓)制作引导层 使用透明的acti
  4. Android中RelativeLayout相对布局
  5. android:inputType参数类型说明
  6. listView分割线
  7. android:lineSpacingExtra,android:lineS
  8. Android: Android中各种onTouch事件
  9. android背景图片平铺
  10. android:inputType参数类型说明