Hello @Nathan Sokalski ,
Welcome to our Microsoft Q&A platform!
In Android, the View
class provides the OnSizeChanged event which will be called when the size of this view has changed. Try creating a custom GridLayout
to rewrite the event. To define the function in the Activity class, you could use delegate
to pass the event.
Check the code:
public class MainActivity : AppCompatActivity
{
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
Xamarin.Essentials.Platform.Init(this, savedInstanceState);
SetContentView(Resource.Layout.activity_main);
CustomLayout layout = FindViewById<CustomLayout>(Resource.Id.parent);
layout.TheChangeEvent += Layout_TheChangeEvent;
}
private void Layout_TheChangeEvent()
{
//perform the work
}
}
Csutom control:
public delegate void SizeChangedEventHanlder();
namespace App19_7
{
public class CustomLayout : GridLayout
{
public CustomLayout(Context context) : base(context)
{
}
public CustomLayout(Context context, IAttributeSet attrs) : base(context, attrs)
{
}
public CustomLayout(Context context, IAttributeSet attrs, int defStyleAttr) : base(context, attrs, defStyleAttr)
{
}
public CustomLayout(Context context, IAttributeSet attrs, int defStyleAttr, int defStyleRes) : base(context, attrs, defStyleAttr, defStyleRes)
{
}
protected CustomLayout(IntPtr javaReference, JniHandleOwnership transfer) : base(javaReference, transfer)
{
}
public event SizeChangedEventHanlder TheChangeEvent;
protected override void OnSizeChanged(int w, int h, int oldw, int oldh)
{
base.OnSizeChanged(w, h, oldw, oldh);
TheChangeEvent.Invoke();
}
}
}
Best Regards,
Jarvan Zhang
If the response is helpful, please click "Accept Answer" and upvote it.
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.