【发布时间】:2015-06-19 05:47:59
【问题描述】:
我正在尝试做一些简单的事情,但这让我非常心痛。我试图务实地创建一个表格布局,添加一行,插入一个图像和一个文本视图。图像应该占据行的25%,其余的应该是TextView。我不拘泥于TableLayout。如果您认为某些东西更好,我会全力以赴,但请它必须是动态/务实的。提前感谢任何帮助的家伙!
这是我尝试过的。当我运行它时,没有任何显示。我有一个 LinearLayout (ll) 我正在尝试将表添加到:
TableLayout tl = new TableLayout(this);
TableRow tr = new TableRow(this);
//add user avatar image
ImageView uivd = new ImageView (this);
param = new LinearLayout.LayoutParams (175,
175);
uivd.Id = idi++;
uivd.SetMaxWidth(175);
uivd.SetMaxHeight(175);
uivd.SetPadding (10, 10, 10, 10);
var vimageBitmap = GetImageBitmapFromUrl (objModel.BaseURL + item.AuthorAvatar);
uivd.SetImageBitmap (vimageBitmap);
param.SetMargins (10, 10, 10, 10);
//add the image to the table row
tr.AddView(uivd,0,param);
//add the textview should take 75% of the width
TextView v = new TextView (this);
v.Id = idi++;
param = new LinearLayout.LayoutParams (ViewGroup.LayoutParams.WrapContent,
ViewGroup.LayoutParams.WrapContent);
param.SetMargins (15, 15, 15, 15);
v.SetBackgroundColor (Color.White);
v.SetTextColor (Color.Black);
v.SetTextSize (Android.Util.ComplexUnitType.Pt, 10);
v.SetBackgroundDrawable (Resources.GetDrawable (Resource.Drawable.textrounded));
v.Text = item.Title +
System.Environment.NewLine +item.Msg;
//add the textview to the table row
tr.AddView (v, 1, param);
//add the table row to the table
tl.AddView (tr);
//add the table to the Linearlayout at the index idx
ll.AddView (tl, idx++, param);
【问题讨论】:
标签: android android-layout xamarin android-tablelayout