简体   繁体   中英

Native Java Android to Xamarin C#

How would I convert this Java code to C#? I am having trouble, specifically on the constructor.

public class MyMediaController extends MediaController
{
    private FrameLayout anchorView;


    public MyMediaController(Context context, FrameLayout anchorView)
    {
        super(context);
        this.anchorView = anchorView;       
    }

    @Override
    protected void onSizeChanged(int xNew, int yNew, int xOld, int yOld)
    {
        super.onSizeChanged(xNew, yNew, xOld, yOld);

        RelativeLayout.LayoutParams lp = (RelativeLayout.LayoutParams) anchorView.getLayoutParams();
        lp.setMargins(0, 0, 0, yNew);

        anchorView.setLayoutParams(lp);
        anchorView.requestLayout();
    }       
}

Your class in Xamarin:

public class MyMediaController : MediaController
{

    private FrameLayout anchorView;


    public MyMediaController(Context context, FrameLayout anchorView) : base(context)
    {
        this.anchorView = anchorView;
    }


    protected override void OnSizeChanged(int xNew, int yNew, int xOld, int yOld)
    {
        base.OnSizeChanged(xNew, yNew, xOld, yOld);

        RelativeLayout.LayoutParams lp = (RelativeLayout.LayoutParams)anchorView.LayoutParameters;
        lp.SetMargins(0, 0, 0, yNew);

        anchorView.LayoutParameters = lp;
        anchorView.RequestLayout();
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM