如何为Xamarin.Android中的线性布局中的子项设置填充/边距?

时间:2017-06-01 05:24:57

标签: xamarin xamarin.android

我可以为线性布局设置填充。但我需要为线性布局中的子项设置填充。请在下面找到我的代码,

    LinearLayout linear1 = new LinearLayout(BaseContext);
    TextView textView = new TextView(BaseContext);
    linear1.AddView(textView,100,100); (or) linear1.AddView(textView,LinearLayout.LayoutParams.MatchParent, LinearLayout.LayoutParams.MatchParent);
    SetContentView(linear1);

现在我需要为线性布局中加载的TextView设置填充。有可能吗?

提前致谢。

2 个答案:

答案 0 :(得分:0)

你可以调用linear1.SetPadding(int,int,int,int);

答案 1 :(得分:0)

我们可以为线性布局中的子项设置填充,如下所示

LinearLayout linear1 = new LinearLayout(BaseContext);
    TextView textView = new TextView(BaseContext);
    linear1.AddView(textView,100,100);

            LinearLayout.LayoutParams options = (LinearLayout.LayoutParams)textView.LayoutParameters; //where textView is the view loaded inside a linear layout.
            options.LeftMargin = 30;
            options.TopMargin = 30;
            options.RightMargin = 30;
            options.BottomMargin = 30;

SetContentView(linear1);