我有问题。我使用自定义适配器创建了GridView。 GridView看起来像这样:
如您所见,列名与列本身不对齐,因为列名是textviews。所以我想做类似的事情,当gridview被填充并且它在第一行时,您首先打印列名。我想要的结果是这样的:
完成后,我想将整个列的列宽调整为最长的值。因此,当我只有“买卖”时,我希望“名称”为“ Action”列,因为它是最长的值。但是,当出现取款值时,它将与该名称一样长。这是我的GridViewAdapter最重要的代码:
public class OrderListAdapter : BaseAdapter<order>
{
public List<order> mItems;
private Context mContext;
public OrderListAdapter(Context context, List<order> items)
{
mItems = items;
mContext = context;
}
public override int Count
{
get { return mItems.Count; }
}
public void refresh(List<order> mItems)
{
this.mItems = mItems;
NotifyDataSetChanged();
}
public override long GetItemId(int position)
{
return position;
}
public override order this[int position]
{
get { return mItems[position]; }
}
public override View GetView(int position, View convertView, ViewGroup parent)
{
View row = convertView;
if (row == null)
{
row = LayoutInflater.From(mContext).Inflate(Resource.Layout.orderlist_row, null, false);
var txtOrderAction = row.FindViewById<TextView>(Resource.Id.txtOrderAction);
var txtOrderCoin = row.FindViewById<TextView>(Resource.Id.txtOrderCoin);
var txtOrderQuantity = row.FindViewById<TextView>(Resource.Id.txtOrderQuantity);
var txtOrderPrice = row.FindViewById<TextView>(Resource.Id.txtOrderPrice);
var txtOrderStatus = row.FindViewById<TextView>(Resource.Id.txtOrderStatus);
var txtOrderProfit = row.FindViewById<TextView>(Resource.Id.txtOrderProfit);
var LayoutProfit = row.FindViewById<LinearLayout>(Resource.Id.LayoutProfit);
row.Tag = new OrderViewHolder() {
txtOrderAction = txtOrderAction,
txtOrderCoin = txtOrderCoin,
txtOrderQuantity = txtOrderQuantity,
txtOrderPrice = txtOrderPrice,
txtOrderStatus = txtOrderStatus,
txtOrderProfit = txtOrderProfit,
LayoutProfit = LayoutProfit };
}
var holder = (OrderViewHolder)row.Tag;
return row;
}
}
使用Order.cs:
public class order
{
public int Id { get; set; }
public int AgentId { get; set; }
public string Action { get; set; }
public string Market { get; set; }
public string Coin { get; set; }
public decimal Quantity { get; set; }
public decimal Amount { get; set; }
public decimal LimitValue { get; set; }
public decimal TriggerValue { get; set; }
public decimal Price { get; set; }
public decimal Trans_Quantity { get; set; }
public decimal Trans_Amount { get; set; }
public decimal Trans_Price { get; set; }
public decimal Trans_Fee_Coin { get; set; }
public decimal Trans_Fee_USDT { get; set; }
public decimal Trans_USDT { get; set; }
public string Status { get; set; }
public string State { get; set; }
public DateTime DateTimeEntered { get; set; }
public DateTime DateTimePlanned { get; set; }
public DateTime DateTimeExecuted { get; set; }
public string Remark { get; set; }
public string Strategy { get; set; }
public decimal ProfitUSDT { get; set; }
public decimal ProfitPerc { get; set; }
}