Hi,
I have some code that generates the UI on the fly. The first time it
runs, it runs a treat. However when I run it again or add something to
the top view, things get messed up (the objects that need to be inflated
become *tiny* at the top but the last object is the correct size)
My code to do this is this
if (clearFirst)
{
RunOnUiThread(delegate {
topListLayout.RemoveAllViewsInLayout();
bottomListLayout.RemoveAllViewsInLayout();
});
}
if (myCircles.Count == 0)
{
myView =
factory.Inflate(Resource.Layout.circleaddFragment, null);
LinearLayout shell = new LinearLayout(context);
shell.Orientation = Orientation.Horizontal;
shell.SetGravity(GravityFlags.CenterVertical);
shell.LayoutParameters = new
LinearLayout.LayoutParams(LinearLayout.LayoutParams.WrapContent,
LinearLayout.LayoutParams.WrapContent);
shell.SetPadding(0, 0, 0,
(int)GeneralUtils.convertDpToPixel(5f, context));
ImageView circleAdd =
myView.FindViewById(Resource.Id.imageCircleAdd);
circleAdd.Click += (object sender, EventArgs e) =>
createCircle(sender, e);
RunOnUiThread(() => shell.AddView(myView));
RunOnUiThread(()=>topListLayout.AddView(shell));
}
else
{
RunOnUiThread(delegate {
LinearLayout topLay = new LinearLayout(context);
topLay.LayoutParameters = new
LinearLayout.LayoutParams(ViewGroup.LayoutParams.WrapContent,
ViewGroup.LayoutParams.WrapContent);
topLay.SetPadding((int)GeneralUtils.convertDpToPixel(5f, context), 0,
(int)GeneralUtils.convertDpToPixel(5f, context), 0);
foreach (Circles circle in myCircles)
{
myView =
factory.Inflate(Resource.Layout.circleFragment, null);
TextView txtCirc =
myView.FindViewById(Resource.Id.textCircleName);
txtCirc.Text = myCircles[count].ShortName;
ImageView imgCirc =
myView.FindViewById(Resource.Id.imageCircle);
int m = new int();
m = count;
imgCirc.Tag = m;
imgCirc.Click += displayMyCircle;
topLay.AddView(myView);
if (count == myCircles.Count || topLay.ChildCount == 3)
{
topListLayout.AddView(topLay);
topLay = new LinearLayout(context);
topLay.Orientation =
Android.Widget.Orientation.Horizontal;
topLay.SetGravity(GravityFlags.CenterHorizontal);
}
count++;
}
myView =
factory.Inflate(Resource.Layout.circleaddFragment, null);
TextView txtCircAdd =
myView.FindViewById(Resource.Id.textCircleName);
txtCircAdd.Text =
GeneralUtils.StringFromInt(Resource.String.circleAdd);
ImageView imgCircAdd =
myView.FindViewById(Resource.Id.imageCircleAdd);
imgCircAdd.Click += createCircle;
topLay.AddView(myView);
topListLayout.AddView(topLay);
});
}
RunOnUiThread(delegate {
count = 0;
LinearLayout botLay = new LinearLayout(context);
botLay.LayoutParameters = new
LinearLayout.LayoutParams(ViewGroup.LayoutParams.WrapContent,
ViewGroup.LayoutParams.WrapContent);
botLay.SetPadding((int)GeneralUtils.convertDpToPixel(5f, context), 0,
(int)GeneralUtils.convertDpToPixel(5f, context), 0);
foreach (Circles circle in OClientData.CirclesList)
{
myView =
factory.Inflate(Resource.Layout.circleFragment, null);
TextView txtCirc =
myView.FindViewById(Resource.Id.textCircleName);
txtCirc.Text =
OClientData.CirclesList[count].ShortName;
ImageView imgCirc =
myView.FindViewById(Resource.Id.imageCircle);
int m = new int();
m = count;
imgCirc.Tag = m;
imgCirc.Click += displayPublicCircle;
botLay.AddView(myView);
if (count == OClientData.CirclesList.Count ||
botLay.ChildCount == 3)
{
bottomListLayout.AddView(botLay);
botLay = new LinearLayout(context);
botLay.Orientation =
Android.Widget.Orientation.Horizontal;
botLay.SetGravity(GravityFlags.CenterHorizontal);
}
if (count + 1 == OClientData.CirclesList.Count)
break;