Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 1st, 2012  |  syntax: None  |  size: 1.10 KB  |  hits: 17  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Programmatically Position Views in RelativeLayout
  2. public override View  GetView(int position, View convertView, ViewGroup parent)
  3.     {
  4.         RelativeLayout rl = new RelativeLayout(context);
  5.         RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.FillParent, ViewGroup.LayoutParams.FillParent);
  6.         ImageView imageView;
  7.         TextView tv;
  8.  
  9.         imageView = new ImageView(context);
  10.         imageView.LayoutParameters = new GridView.LayoutParams(250, 250);
  11.         imageView.SetScaleType(ImageView.ScaleType.CenterCrop);
  12.         imageView.SetPadding(8, 8, 8, 8);
  13.         imageView.SetImageResource(thumbIds[position]);
  14.         imageView.Id = position;
  15.  
  16.         lp.AddRule(LayoutRules.Below, position);
  17.         lp.AddRule(LayoutRules.CenterHorizontal);
  18.  
  19.         tv = new TextView(context);
  20.         tv.Text = stringIds[position].ToString();
  21.         tv.SetTextSize(Android.Util.ComplexUnitType.Dip, 20);
  22.         tv.SetTextColor(Android.Graphics.Color.WhiteSmoke);
  23.         tv.LayoutParameters = lp;
  24.  
  25.         rl.AddView(imageView);
  26.         rl.AddView(tv);
  27.  
  28.         return rl;
  29.     }