如何以编程方式设置线性布局边距(Xamarin)

时间:2018-01-08 10:09:58

标签: android xamarin android-linearlayout

我的布局xml中有一个线性布局:

<LinearLayout
    android:id="@+id/loginForm_LinearLayout" `
    android:orientation="vertical" 
   android:layout_width="220dp" 
    android:layout_height="wrap_content" 
    android:layout_centerHorizontal="true"> 

         ...some item... 

</LinearLayout>    `

但是当程序运行时,我必须更改此Linear Layout的保证金顶部。怎么能在xamarin中做到?

1 个答案:

答案 0 :(得分:0)

试试这个

 LinearLayout.LayoutParams ll = new LinearLayout.LayoutParams (ViewGroup.LayoutParams.FillParent, ViewGroup.LayoutParams.FillParent);

 ll.SetMargins (0,0,0,10);
 mainPanel.LayoutParameters = ll

OR

var mainPanel = FindViewById<LinearLayout>(Resource.Id.mainasdf);
var linearLayoutParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.FillParent,
                                                      ViewGroup.LayoutParams.FillParent);
linearLayoutParams.SetMargins(0, 0, 0, 0);
mainPanel.LayoutParameters = linearLayoutParams