Android点滴

时间:2023-03-09 05:48:16
Android点滴

1,View中getWidth(),getLayoutParams.width,getMeasureedWidth()的区别

2,setCompoundDrawables和setCompoundDrawablesWithIntrinsicBounds 的区别

1,View中getWidth(),getLayoutParams.width,getMeasureedWidth()的区别

getWidth()在layout执行完后才能获取宽度,在onMeasure()方法中是拿不到的 
  而固定宽度,可以通过layoutParams.width获取,如果是wrap_content也是不能获取的 
getLayoutParams.width可以在onMesure方法中获取 
getMeasureedWidth();在onMeasure()执行完后才会有值

Height也就类似了。。。

2,setCompoundDrawables和setCompoundDrawablesWithIntrinsicBounds 的区别

setCompoundDrawables是要drawable自己设置自己的Bounds,而setCompoundDrawablesWithIntrinsicBounds不用自己设置,会根据drawable的大小来适应

setCompoundDrawablesWithIntrinsicBounds 中,drawable的宽高是通过getIntrinsicWidth()与getIntrinsicHeight()获得。

3,