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

如:

宽度上按比例显示

<LinearLayout
android:layout_marginTop="5dp"
android:orientation="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"
android:orientation="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进阶学习】实现没有标题栏的窗口和全屏显示
  2. Android之ListView中的分割线
  3. Android(安卓)studio教程学习笔记4——TextView
  4. Android:漫画APP开发笔记之ListView中图片按屏幕宽度缩放
  5. Android中TextVIew一些属性
  6. Android(安卓)share绘制虚线在手机上显示实线问题
  7. TextView显示链接
  8. Android(安卓)HDMI( 三)
  9. Android(安卓)学习记录-ImageView显示格式

随机推荐

  1. Android中的dispatchTouchEvent()、onInt
  2. 粘贴复制Android复制和粘贴的实现
  3. Android签名制作apk
  4. Failure [INSTALL_FAILED_TEST_ONLY: ins
  5. Android(安卓)文件存储--内部存储的例子
  6. android webview 设置
  7. Android全屏(包含3种隐藏顶部状态栏及标题
  8. Android(安卓)Junit 单元测试步骤
  9. 【Android(安卓)界面效果4】android背景
  10. Android(安卓)拍照及相册选图的那些坑