簡體   English   中英

原生Java Android到Xamarin C#

[英]Native Java Android to Xamarin C#

如何將Java代碼轉換為C#? 我遇到了麻煩,特別是在構造函數上。

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();
    }       
}

您在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();
    }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM