问题遇到的现象和发生背景
问题相关代码,请勿粘贴截图
<TableLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:stretchColumns="*"
android:layout_columnSpan="4"
android:id="@+id/TableLayout1">
</TableLayout>
tableRow.AddView(_dynaControl.AddButton(this, string.Format("{0} ", "编辑"), Android.Graphics.Color.White, "编辑"+ mo.id, Button_修改_Click));
tableRow.AddView(_dynaControl.AddButton(this, string.Format("{0} ", "删除"), Android.Graphics.Color.White, "删除"+ mo.id, Button_删除_Click));
tableRow.AddView(_dynaControl.AddButton(this, string.Format("{0} ", mo.本商品备注), Android.Graphics.Color.White, "本商品备注" + mo.id, null));
public Button AddButton(Context context, string text,Android.Graphics.Color 背景色 , Java.Lang.Object tag, EventHandler clickAction = null)
{
var btn = new Button(context);
btn.Tag = tag;
btn.SetBackgroundColor(背景色);
btn.SetText(text, TextView.BufferType.Normal);
btn.SetPadding(0, 0, 0, 0);
//btn.SetHeight(35);
btn.SetWidth(80);
int width = 0;
if (text!=null)
{
if (text.Length==0)
{
width = 600;
}
else
{
width += text.Length * 100;
}
}
Drawable dr = ContextCompat.GetDrawable(context, Resource.Drawable.Biankuang12);
Bitmap bitmap = ((BitmapDrawable)dr).Bitmap;
BitmapDrawable mobile_drawable = new BitmapDrawable(Android.Content.Res.Resources.System, Bitmap.CreateScaledBitmap(bitmap, 2, 200, true));
Drawable dr2 = ContextCompat.GetDrawable(context, Resource.Drawable.Biankuang);
Bitmap bitmap2 = ((BitmapDrawable)dr2).Bitmap;
BitmapDrawable mobile_drawable2 = new BitmapDrawable(Android.Content.Res.Resources.System, Bitmap.CreateScaledBitmap(bitmap2, width, 2, true));
btn.SetCompoundDrawablesWithIntrinsicBounds(mobile_drawable, mobile_drawable2, mobile_drawable, mobile_drawable2);
if (clickAction != null)
{
btn.Click += clickAction;
}
return btn;
}
运行结果及报错内容
我的解答思路和尝试过的方法
我想要达到的结果
TableLayout实现边框布局位置不偏移