hey bro in a case like this where you are calling runonuithread a lot, I
would, for readability, pass to named function instead of delegate. This
really improves readability.


On Wed, May 15, 2013 at 1:02 PM, Paul Johnson
<[email protected]>wrote:

> 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<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
> [email protected]
>
> UNSUBSCRIBE INFORMATION:
> http://lists.ximian.com/**mailman/listinfo/monodroid<http://lists.ximian.com/mailman/listinfo/monodroid>
>



-- 
Extreme Knowledge is not something for which he programs a computer but for
which his computer is programming him.

-Wozniak


   - if my programming advice has helped you, feel free to donate to :
<https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=KYUXV2PG88YQQ>

<https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=KYUXV2PG88YQQ>
<https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=KYUXV2PG88YQQ>
_______________________________________________
Monodroid mailing list
[email protected]

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

Reply via email to