Converted FlowLayout.java won't process xml paramaters

revcomrevcom Robert CragoAUMember
edited October 2012 in Xamarin.Android

Hi there,

I have downloaded and converted Romain Guy's FlowLayout.java to C# under Mono for Android from: github

The converted code works fine for a couple of different layouts, except that the parameters passed in the xml file are being ignored (for example flow:horizontalSpacing) resulting in the buttons being squashed together instead of spread out. If I supply the spacing settings in code, it works fine so I suspect that my code conversion is amiss somewhere.

The only code changes I made (apart from those required by Java/C# differences) were the "public static class LayoutParams extends ViewGroup.LayoutParams" had to become "public new class LayoutParams: ViewGroup.LayoutParams" as C# would not accept this class being static without significant surgery. (I also had to make this class's private layout members public temporarily so I could work around the problem by setting them externally in code)

Many thanks for your help...

Robert

The converted FlowLayout.cs is attached. My xml layout file follows:

<LinearLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:flow="pi3prototype.customlayouts"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:paddingTop="4dip">

  <pi3prototype.customlayouts.FlowLayout
    android:id="@+id/pnlControlPanel"
   _ flow:horizontalSpacing="5dip"
    flow:verticalSpacing="5dip"_
    android:layout_width="fill_parent"
    android:layout_height="wrap_content">

    <Button
      android:id="@+id/btnDELETE"
      android:focusable="false"
      android:layout_height="40dip"
      android:layout_width="100dip"
      android:background="@drawable/btn2"
      android:text="DELETE"/>

    <Button
     android:id="@+id/btnDETAILS"
     android:focusable="false"
     android:layout_height="40dip"
     android:layout_width="100dip"
     android:background="@drawable/btn2"
     android:text="DETAILS"/>

    <Button
      android:id="@+id/btnCOPY"
      android:focusable="false"
      android:layout_height="40dip"
      android:layout_width="100dip"
      android:background="@drawable/btn2"
      android:text="COPY"/>

    <Button
      android:id="@+id/btnINSPECT"
      android:focusable="false"
      android:layout_height="40dip"
      android:layout_width="100dip"
      android:background="@drawable/btn1"
      android:text="INSPECT"/>

    <Button
      android:id="@+id/btnAPI"
      android:focusable="false"
      android:layout_height="40dip"
      android:layout_width="100dip"
      android:background="@drawable/btn1"
      android:text="API"/>

    <Button
      android:id="@+id/btnFLER"
      android:focusable="false"
      android:layout_height="40dip"
      android:layout_width="100dip"
      android:background="@drawable/btn1"
      android:text="FLER"/>
  </pi3prototype.customlayouts.FlowLayout>
</LinearLayout>

Posts

  • brajkovicbrajkovic Bojan Rajkovic USXamarin Team, University Xamurai

    Hi @revcom,

    Welcome to the Xamarin forums! You write in your post that you attached a converted .cs file, but it doesn't seem to have actually attached anything. Can you try attaching it again to another reply on this thread?

    Thanks,
    Bojan

  • revcomrevcom Robert Crago AUMember

    Hi Bojan,

    My apologies - my browser (IE9) is not playing nice with the forum site.

    I'll try the attach again...

    Robert

  • revcomrevcom Robert Crago AUMember

    Hi Bojan,

    Uploaded .cs file ok this time - had to be zipped to be acceptable

    Thanks...

    Robert

  • CheesebaronCheesebaron Tomasz Cielecki DKInsider, University mod

    I did some cleanup of the code and got it to work. There are some issues with some colors. But I think your main issue lies in when you define your axml your flow namespace is pointing somewhere not known. You forgot to add http://schemas.android.com/apk/res/ before your namespace.

    I have attached my test project so you can see what I have done.

  • revcomrevcom Robert Crago AUMember

    Thanks Tomasz,

    Appreciate your help - will check it out when I get to work on Monday

    Robert

  • hdpavanhdpavan pavan deshpande INMember

    Hi

    Android linear layout, as the name suggests, all the elements(like textview , button ,…) are displayed in a linear fashion, either Horizontally or Vertically and this behavior is set in android: orientation which is an attribute of the node Linear Layout. -

    check this link where the linear layout is explained in detail Android Linear Layout

  • AndreyKozhynAndreyKozhyn Andrey Kozhyn USMember ✭✭

    If I add atts.xml into project, I'm getting runtime exception:

    05-20 15:57:09.948 E/AndroidRuntime( 3443): Caused by: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
    05-20 15:57:09.948 E/AndroidRuntime( 3443):     at android.support.v7.app.AppCompatDelegateImplBase.onCreate(AppCompatDelegateImplBase.java:113)
    05-20 15:57:09.948 E/AndroidRuntime( 3443):     at android.support.v7.app.AppCompatDelegateImplV7.onCreate(AppCompatDelegateImplV7.java:146)
    05-20 15:57:09.948 E/AndroidRuntime( 3443):     at android.support.v7.app.AppCompatActivity.onCreate(AppCompatActivity.java:59)
    05-20 15:57:09.948 E/AndroidRuntime( 3443):     at md524b9abcb918ccd3c513bdef043ad759c.MvxActionBarActivity.n_onCreate(Native Method)
    05-20 15:57:09.948 E/AndroidRuntime( 3443):     at md524b9abcb918ccd3c513bdef043ad759c.MvxActionBarActivity.onCreate(MvxActionBarActivity.java:63)
    05-20 15:57:09.948 E/AndroidRuntime( 3443):     at android.app.Activity.performCreate(Activity.java:5990)
    05-20 15:57:09.948 E/AndroidRuntime( 3443):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106)
    05-20 15:57:09.948 E/AndroidRuntime( 3443):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2278)      
    

    What could be the reason? I don't change anything in the project except adding attrs.xml. Without this file application works without any issues.

  • AceChalhoubAceChalhoub Ace Chalhoub USMember

    Is it possible to have the full working flowlayout? I tried it but seem to be missing the Styleables

    Resource.Styleable.FlowLayout_horizontalSpacing--> NOT FOUND

    thanks

Sign In or Register to comment.