Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/xamarin/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在Xamarin.Android中为线性布局中的子级设置填充/边距?_Xamarin_Xamarin.android - Fatal编程技术网

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

如何在Xamarin.Android中为线性布局中的子级设置填充/边距?,xamarin,xamarin.android,Xamarin,Xamarin.android,我可以设置线性布局的填充。但是我需要在线性布局中为孩子们设置填充。请在下面找到我的代码 LinearLayout linear1 = new LinearLayout(BaseContext); TextView textView = new TextView(BaseContext); linear1.AddView(textView,100,100); (or) linear1.AddView(textView,LinearLayout.LayoutParams.Ma

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

    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设置填充。可能吗


提前谢谢。

您可以调用linear1.SetPadding(int,int,int,int)

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

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

如果我们这样调用,填充将应用于线性布局,而不是其子级。