I just did a small test and successfully added margins to a
LinearLayout. I just used the default layout from a new Mono for
Android project and added an id (@+id/Layout) to the LinearLayout in
the Mail.axml file.

Then in the OnCreate method of the Activity I just added the following code:

LinearLayout l = FindViewById<LinearLayout>(Resource.Id.Layout);

LinearLayout.MarginLayoutParams lp = (ViewGroup.MarginLayoutParams)
l.LayoutParameters;
lp.SetMargins(25, 25, 25, 25);

This works just fine.

On Tue, May 29, 2012 at 10:21 AM, Goncalo Oliveira <[email protected]> wrote:
> Can't seem to set margins with code bellow. Only way I can get this to work
> with margins is to add it directly in the xml.
>
> LinearLayout view = FindViewById<LinearLayout>( Resource.Id.taskDetailView
> ); // vertical linear layout
> TextView childView = new TextView( this );
>
> childview.SetText( "some text" );
>
> LinearLayout.MarginLayoutParams layoutParams = new
> LinearLayout.MarginLayoutParams( ViewGroup.LayoutParams.FillParent,
> ViewGroup.LayoutParams.WrapContent );
>
> layoutParams.TopMargin = <some pixel value... let's say 6>
> // also tried layoutParams.SetMargins( .... )
>
> view.AddView( childView, layoutParams );
>
> The xml declaration is pretty simple.
>
>         <LinearLayout
>             android:orientation="vertical"
>             android:minWidth="25px"
>             android:minHeight="25px"
>             android:id="@+id/taskDetailView"
>             android:layout_width="fill_parent"
>             android:layout_height="wrap_content" />
>
>
> There's no relevant trace in logcat
>
> I/ActivityManager(  196): [AppLaunch] Displayed
> Frotcom.FMobile/fmobile.activities.TaskDetailsActivity: +484ms
> D/ActivityManager(  196):
> AP_PROF:AppLaunch_LaunchTime:Frotcom.FMobile/fmobile.activities.TaskDetailsActivity:484:448651969
> I/SurfaceFlinger(  196): [SurfaceFlinger] statistic - FrameCount: 120,
> Duration: 17477341us, fps: 6.866034
> I/KeyguardUpdateMonitor(  196): DM_IsLocked, lockflag is false
> D/dalvikvm(  196): GC_CONCURRENT freed 1797K, 43% free 6611K/11399K,
> external 3983K/6031K, paused 14ms+17ms
> D/OSFileSystem(  196): OSFileSystem::open fail :
> filename==/sys/devices/system/cpu/cpu0/cpufreq/stats/time_in_state, errno=2,
> err=No such file or directory
> D/WifiCommon(  196): [wlan0] Issue cmd = 'DRIVER RSSI-APPROX'
> D/WifiCommon(  196): [wlan0] cmd = 'DRIVER RSSI-APPROX' ==> failed. (ret = 0
> or reply='FAIL').
> D/WifiCommon(  196): [wlan0] Issue cmd = 'DRIVER RSSI'
> D/WifiStateTracker(  196): requestPolledInfo, newRssi=-66
> D/WifiCommon(  196): [wlan0] Issue cmd = 'DRIVER LINKSPEED'
> D/WarningMessage(  323): TimerTask: ReadCodeTask.run()
> D/WarningMessage(  323): sendWarningMessage() called.
> D/WarningMessage(  323): line content: 0
> D/WarningMessage(  323): notify code is 0
> D/WarningMessage(  323): getWarningMessage() called.
> D/WifiCommon(  196): [wlan0] Issue cmd = 'DRIVER RSSI-APPROX'
> D/WifiCommon(  196): [wlan0] cmd = 'DRIVER RSSI-APPROX' ==> failed. (ret = 0
> or reply='FAIL').
> D/WifiCommon(  196): [wlan0] Issue cmd = 'DRIVER RSSI'
> D/WifiStateTracker(  196): requestPolledInfo, newRssi=-66
> D/WifiCommon(  196): [wlan0] Issue cmd = 'DRIVER LINKSPEED'
>
>
> On 28 May 2012 19:14, Jonathan Pryor <[email protected]> wrote:
>>
>> On May 28, 2012, at 12:29 PM, Goncalo Oliveira wrote:
>> > This fails.
>>
>> Can you elaborate? Presumably there's an exception in the Android Debug
>> Log (`adb logcat`); can you provide the full stack trace?
>>
>> Thanks,
>>  - Jon
>>
>> _______________________________________________
>> Monodroid mailing list
>> [email protected]
>>
>> UNSUBSCRIBE INFORMATION:
>> http://lists.ximian.com/mailman/listinfo/monodroid
>
>
>
>
> --
> Gonçalo Oliveira
>
> _______________________________________________
> Monodroid mailing list
> [email protected]
>
> UNSUBSCRIBE INFORMATION:
> http://lists.ximian.com/mailman/listinfo/monodroid
>



-- 
Med Venlig Hilsen / With Best Regards
Tomasz Cielecki
http://ostebaronen.dk
_______________________________________________
Monodroid mailing list
[email protected]

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

Reply via email to