MonoDroid:如何以编程方式设置TableRow背景属性?

时间:2011-09-16 18:50:57

标签: xamarin.android

我正在尝试动态创建一些表行,但在Table Row上我想设置背景 像这样的XML属性:

< TableRow android:background =“@ drawable / shape”android:layout_marginBottom =“5dip”>

我试过了:

TableRow.LayoutParams p = new TableRow.LayoutParams(this,null);

但是没有p.AddRule方法? (引自:Setting layout properties in code at runtime

我想我需要构建params然后将它们传递给 TableRow row = new TableRow(this,p);

想法?

2 个答案:

答案 0 :(得分:0)

AddRule()RelativeLayout.LayoutParams上的一种方法。您需要转换为该类型或以其他方式获取它,即:

var p = new RelativeLayout.LayoutParams (this, null);
p.AddRule(LayoutRules.AlignParentBottom);

答案 1 :(得分:0)

想出来:row.SetBackgroundResource(Resource.Drawable.shape);