如何在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);
如果我们这样调用,填充将应用于线性布局,而不是其子级。