关于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,表示该控件不会被拉伸以适应布局;其他值则表示,控件在布局空白区域中的占地比例。

结合实际例子来看看:
Android layout_weight案例分析总结_第1张图片

<?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即可。
Android layout_weight案例分析总结_第2张图片
Android layout_weight案例分析总结_第3张图片

更多相关文章

  1. Android--取得布局中指定控件的宽高
  2. Android oncreate中获取控件宽高
  3. android计算器布局(TableLayout)
  4. 控件 - ImageView
  5. 四大布局
  6. android开发4:Android布局管理器1(线性布局,相对布局RelativeLayou
  7. RelativeLayout(相对布局)
  8. Android基础————UI布局之高级控件详解
  9. Android常用控件—TextView及其子类Button、EditText等

随机推荐

  1. IJKPlayer/FFMPEG 4 Android
  2. android连续按两次返回退出程序(完整代码)
  3. Android(安卓)中的看门狗—Watchdog
  4. Android中Socket通讯类
  5. How to install Android(安卓)SDK in Ubu
  6. android Multiple markers at this line
  7. Android获取通话记录
  8. How to Cross Compile the Bash shell fo
  9. Android(安卓)之 SeekBar用法介绍
  10. How to compile Android(安卓)1.6 (Andro