开发者

MonoDroid: How to programatically set TableRow background attribute?

I'm trying to dynamically create some table rows, but on the Table Row I want to set the background attribut开发者_运维百科e like this XML:

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

I tried this:

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

but there is no p.AddRule method? (as quoted from: Setting layout properties in code at runtime)

I think I need to construct the params then pass them into the TableRow row = new TableRow(this, p);

Ideas?


AddRule() is a method on RelativeLayout.LayoutParams. You need to either cast to that type or acquire it otherwise, i.e. :

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


Figured it out: row.SetBackgroundResource(Resource.Drawable.shape);

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜