Can't cast LayoutParameters

时间:2016-04-04 18:23:39

标签: c# android xamarin

My namespace contains the word Android, therefore I have to work around the following problem: I want to change the bottom margin of my RelativeLayout.

public RelativeLayout RelativeLayout { get; set; }

RelativeLayout.LayoutParams relativeParams 
= (global::Android.Widget.RelativeLayout.LayoutParams)_RelativeLayout.LayoutParameters;
relativeParams.SetMargins(0, 0, 0, 10);
_RelativeLayout.LayoutParameters = relativeParams;

This gives me an InvalidCastException right at the first line. What am I doing wrong?

1 个答案:

答案 0 :(得分:0)

如果它必须包含平台,我建议将命名空间更改为Droid之类的东西。在你的命名空间中使用Android会比其他任何东西都更有害,因为你必须经常找到解决这种微小变化的方法。