//先用layoutinflater搞成一个view然后再调用方法测量
MarkMapAnchorBinding markMapAnchorBinding = MarkMapAnchorBinding.inflate(getLayoutInflater());
getHeight(activity,binding.getRoot());
public static int getHeight(BaseActivity context, View v){
DisplayMetrics metric =new DisplayMetrics();
context.getWindowManager().getDefaultDisplay().getMetrics(metric);
int width = metric.widthPixels;
int height = metric.heightPixels;
int measuredWidth = View.MeasureSpec.makeMeasureSpec(width, View.MeasureSpec.EXACTLY);
int measuredHeight = View.MeasureSpec.makeMeasureSpec(height, View.MeasureSpec.AT_MOST);
v.measure(measuredWidth, measuredHeight);
return v.getMeasuredHeight();
}
View没有加载在布局上,还想测量View的宽和高
最新推荐文章于 2023-12-08 15:20:50 发布