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<ImageView>(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<TextView>(Resource.Id.textCircleName);

                        txtCirc.Text = myCircles[count].ShortName;
ImageView imgCirc = myView.FindViewById<ImageView>(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<TextView>(Resource.Id.textCircleName); txtCircAdd.Text = GeneralUtils.StringFromInt(Resource.String.circleAdd); ImageView imgCircAdd = myView.FindViewById<ImageView>(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<TextView>(Resource.Id.textCircleName);

txtCirc.Text = OClientData.CirclesList[count].ShortName; ImageView imgCirc = myView.FindViewById<ImageView>(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;
                    count++;
            }
myView = factory.Inflate(Resource.Layout.circleaddFragment, null); TextView txtCircAdd = myView.FindViewById<TextView>(Resource.Id.textCircleName); txtCircAdd.Text = GeneralUtils.StringFromInt(Resource.String.circleAdd); ImageView imgCircAdd = myView.FindViewById<ImageView>(Resource.Id.imageCircleAdd);
                imgCircAdd.Click += createCircle;
                botLay.AddView(myView);
                bottomListLayout.AddView(botLay);
            });

The circles are the correct size at the bottom, just not at the top. The circles are really simple

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android";
    android:orientation="vertical"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content">
    <LinearLayout
        android:orientation="vertical"
        android:minWidth="25px"
        android:minHeight="25px"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/linearLayout5"
        android:gravity="center_horizontal"
        android:layout_weight="1">
        <TextView
            android:text="@string/circleBlank"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/textCircleName"
            android:textColor="#000" />
        <ImageView
            android:src="@drawable/emptycircle"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:id="@+id/imageCircle" />
    </LinearLayout>
</LinearLayout>

Any help or advice here would be appreciated.

Thanks

Paul
--
"Space," it says, "is big. Really big. You just won't believe how vastly, hugely, mindbogglingly big it is. I mean, you may think it's a long way down the road to the chemist's, but that's just peanuts to space, listen..."
Hitch Hikers Guide to the Galaxy, a truly remarkable book!

_______________________________________________
Monodroid mailing list
Monodroid@lists.ximian.com

UNSUBSCRIBE INFORMATION:
http://lists.ximian.com/mailman/listinfo/monodroid

Reply via email to