2017-07-12 2 views
-1

Wie würde ich diesen Java-Code in C# konvertieren? Ich habe Probleme, speziell beim Konstruktor.Native Java Android zu Xamarin 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(); 
    }  
} 

Antwort

2

Ihre Klasse 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(); 
    } 
} 
+1

this.OnSizeChanged (Xneu, Ynew, Xalt, yold); sollte base.OnSizeChanged (xNew, yNew, xOld, yOld) sein; – lowleetak

+0

Danke, ich habe es geändert! –

+0

Danke, was ist das? ((ViewGroup) mediaController.getParent()). RemoveView (mediaController); // Fügen Sie den MediaController zu einem FrameLayout in Ihrem DialogFragment hinzu. ((FrameLayout) findViewById (R.id.controlsWrapper)). AddView (mediaController); – guybrushThreepwood