final CustomView custom_view = (CustomView) findViewById(R.id.custom_view);
custom_view.measure(0, 0);
custom_view.post(new Runnable() {
@Override
public void run() {
int width= custom_view.getMeasuredWidth();
int height = custom_view.getMeasuredHeight();
Log.e(TAG, "width="+width);
Log.e(TAG, "height="+height);
}
custom_view.measure(0, 0);
custom_view.post(new Runnable() {
@Override
public void run() {
int width= custom_view.getMeasuredWidth();
int height = custom_view.getMeasuredHeight();
Log.e(TAG, "width="+width);
Log.e(TAG, "height="+height);
}
});
没啥好解释的
本文介绍了一种在Android中测量自定义视图尺寸的方法。通过使用measure()方法并结合post()方法,在主线程中获取到自定义视图的宽度和高度,并通过Log输出具体数值。
1587

被折叠的 条评论
为什么被折叠?



