I am trying to create a button in Xamarin android with an image above it. doing some googling i found that there is something in the axml u can use called drawabletop. however my buttons are created programmatically, so in want to know how i can fill in this parameter outside of the axml. button.drawabletop does not exist.
private async void LoadCardList(string code)
{
CardDataService cardDataService = new CardDataService(new CardRepo());
Cards = await cardDataService.GetCardsAsync(code);
TableLayout ll = View.FindViewById<TableLayout>(Resource.Id.cardlist);
TableRow.LayoutParams lp = new TableRow.LayoutParams(LinearLayout.LayoutParams.MatchParent, LinearLayout.LayoutParams.MatchParent);
var i = 0;
var row = new TableRow(this.Activity);
row.WeightSum = 2;
var sortedCards = Cards.OrderBy(o => o.number).ToList();
foreach (var cards1 in sortedCards)
{
var b = new Button(this.Activity);
b.Text = cards1.name;
lp.Weight = 1;
b.LayoutParameters = lp;
row.AddView(b);
i++;
if (i > 1)
{
ll.AddView(row, new TableLayout.LayoutParams(TableLayout.LayoutParams.MatchParent, TableLayout.LayoutParams.WrapContent));
row = new TableRow(this.Activity);
row.LayoutParameters = lp;
i = 0;
}
}
this is my method where i do everything. those buttons i create are the ones i want to have an image. the sortedCards list also contains an image.
regards,
Bjorn