1:android得到view的长度可以通过getMeasureWidth getWidth 但是比如在一个view的构造方法或者初始化时候 用getWidth那么就是0,而getMeasureWidth只是粗略的估计了一下view的宽高,在调用getMeasureWidth 之前 调用 measure(0,0) 否则会得到0
2: getMeasuerWidth 不一定准确 比如 以下布局
<LinearLayout
android:layout_width="fill_parent"
android:oritation="horizontal"
android:layout_height="wrap_content"
<LinearLayout
android:id="@+id/ll_01"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1" >
<RadioButton
android:id="@+id/rd01"
android:layout_width="fill_parent"
android:layout_height="100dip"
android:background="@color/white"
android:button="@null"
android:checked="true"
android:drawableBottom="@null"
android:drawableLeft="@null"
android:drawableRight="@null"
android:drawableTop="@drawable/selector_color_white_light_blue"
android:gravity="center_horizontal|bottom"
android:paddingBottom="10dip"
android:text="全部" />
</LinearLayout>
<LinearLayout
android:id="@+id/ll_02"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1" >
<RadioButton
android:id="@+id/rd02"
android:layout_width="fill_parent"
android:layout_height="100dip"
android:background="@color/white"
android:button="@null"
android:checked="true"
android:drawableBottom="@null"
android:drawableLeft="@null"
android:drawableRight="@null"
android:drawableTop="@drawable/selector_color_white_light_blue"
android:gravity="center_horizontal|bottom"
android:paddingBottom="10dip"
android:text="全部" />
</LinearLayout>
</LinearLayout>
这里面需要注意的是 当我们把一个view设置为fillparent 或者设置权重的时候 我们通过getMeasuerWidth得到的宽度是不准确的,
raidiobutton的通过getMeasuerWidth得到的宽度 实际上是文字的宽度
所以一般我们在view的ondraw方法 和onLayout方法里面 通过getWidth得到宽度(并且在父view的onLayout方法里面也能通过子view的getWIdth得到宽度);