关于layout_weight,我们一般就理解为布局权重的意思,Android官方的说明如下:
Formats: float
Indicates how much of the extra space in the LinearLayout is allocated to the view associated with these LayoutParams. Specify 0 if the view should not be stretched. Otherwise the extra pixels will be pro-rated among all views whose weight is greater than 0.

可赋值类型为float,
layout_weight的含义是:在线性布局中,这些控件各自占据的空白区域的比重。
为0,表示该控件不会被拉伸以适应布局;其他值则表示,控件在布局空白区域中的占地比例。

结合实际例子来看看:

<?xml version="1.0" encoding="utf-8"?>:android="http://schemas.android.com/apk/res/android"    android:layout_width="fill_parent"    android:layout_height="fill_parent"    android:orientation="vertical" >    :layout_width="match_parent"        android:layout_height="wrap_content"        android:layout_weight="1"        android:orientation="horizontal">        

上面的布局整体由一个竖向的LinearLayout填满画布,然后再由一个横向的LinearLayout和一个listView组成它的两部分,横向LinearLayout包含两个按钮。我们主要看的是listview的摆放。显然,按钮的比重需要小,列表的比重需要大。所以,我们通过制定layout_weight一小一大,就可以了,分别为1和9,当然个人喜好问题了。
至于按钮和listview的宽和高,我们需要根据实际情况来布局,一般来说,在下面的布局中,我们需要将宽度和画布的宽度设置为一样大,不然就不好看了。而高度则是以字体的大小来定的,所以设置为wrap_content即可。

更多相关文章

  1. Android用户界面设计
  2. Android(安卓)oncreate中获取控件宽高
  3. Android中隐藏ActionBar的方法
  4. 控件 - ImageView
  5. Android(安卓)ListView getView()方法重复调用导致position错位
  6. 四大布局
  7. android开发4:Android布局管理器1(线性布局,相对布局RelativeLayou
  8. RelativeLayout(相对布局)
  9. android EditText 全面阐述

随机推荐

  1. Ubuntu搭建android编译环境总结
  2. Android 使用腾讯TBS遇到的坑
  3. android练习一之走马灯效果
  4. android——写xml
  5. Android 实现两屏幕互相滑动
  6. 学习Android camera笔记 & 调用流程
  7. 通过UserAgent判断智能手机(设备,Android
  8. 13-7-5 android Tabhost功能实现
  9. Android直接播放麦克风采集到的声音
  10. android Q的init rc脚本创建目录失败问题