Hello,
Welcome to our Microsoft Q&A platform!
You can try to use AddOnGlobalLayoutListener
to measture height of a framelayout,
FrameLayout gamearea = FindViewById<FrameLayout>(Resource.Id.frameLayout1);
gamearea.ViewTreeObserver.AddOnGlobalLayoutListener(new MyOnGlobalLayoutListenter(gamearea));
Then achieve the MyOnGlobalLayoutListenter.cs
.
internal class MyOnGlobalLayoutListenter : Java.Lang.Object, ViewTreeObserver.IOnGlobalLayoutListener
{
private FrameLayout frameLayout1;
public MyOnGlobalLayoutListenter(FrameLayout frameLayout1)
{
this.frameLayout1 = frameLayout1;
}
public void OnGlobalLayout()
{
int value= getViewHeight(frameLayout1);
Console.WriteLine("Get the height of a framelayout"+ value);
}
int getViewHeight(View view)
{
int WidthSpec= View.MeasureSpec.MakeMeasureSpec(0,MeasureSpecMode.Unspecified);
int HeightSpec = View.MeasureSpec.MakeMeasureSpec(0, MeasureSpecMode.Unspecified);
View.MeasureSpec.MakeMeasureSpec(0, MeasureSpecMode.Unspecified);
view.Measure(WidthSpec, WidthSpec);
int mesurewitdth=view.MeasuredHeight;
return mesurewitdth;
}
}
Best Regards,
Leon Lu
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.