0x00 需求:
根据控件(ImageView)来决定画布的大小(width height)
0x01 :
等界面(Activity)加载完成;
0x02 参考:
http://blog.csdn.net/heng615975867/article/details/9358679
image = (ImageView)findViewById(R.id.ImageView01);
//height = image.getHeight();
//width = image.getWidth();
//Log.d(TAG, "height: " + height);
//Log.d(TAG, "width: " + width);
LayoutParams para;
para = image.getLayoutParams();
Log.d(TAG, "layout height0: " + para.height);
Log.d(TAG, "layout width0: " + para.width);
0x03 :
等待界面Layout完成
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
((SeekBar)findViewById(R.id.seekBar)).setOnSeekBarChangeListener(this);
//1 第一步执行
final View iv = null;
iv.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
//3 第三步执行
int height = iv.getHeight();
int width = iv.getWidth();
func();
iv.getViewTreeObserver().removeGlobalOnLayoutListener(this);
}
});
//2 第二步执行
}
0xFF :
代码未完成!
其中para = image.getLayoutParams()不能用,获取到的都是-1,无论是否加载完成。
image.getWidth();可用。