You need use a subclass of LayoutParams specific to the enclosing layout's
class.  In this case,  RelativeLayout.LayoutParams (IIRC, typing this from
a phone).

Also note: top/left alignment is the default.
21.02.2012 18:46 пользователь "Marcin Orlowski" <[email protected]>
написал:

> Hi,
>
> I got a relative layout to which I want to add some manually positioned
> childs. The thing I failed
> to do correctly now is the latter - enforcing certain position of the
> child. If anyone knows
> what I am doing wrong...
>
> My "parent layout":
>
>         <RelativeLayout
>             android:id="@+id/container"
>             android:layout_width="fill_parent"
>             android:layout_height="110dp" >
>         </RelativeLayout>
>
> the "child" empty linear layout, inflated (because I am not sure I can
> set layout_alignParentXXX from code...) from this XML (box.xml):
>
> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android";
>     android:layout_width="50dp"
>     android:layout_height="50dp"
>     android:layout_alignParentTop="true"
>     android:layout_alignParentLeft="true"
>     >
> </LinearLayout>
>
> My idea of placing it whenever I want is to adjust layout_marginTop and
> layout_marginLeft.
> This is what I do:
>
>        RelativeLayout containerView = (RelativeLayout)findViewById(
> R.id.container );
>        LinearLayout l = (LinearLayout)this.getLayoutInflater().inflate(
> R.layout.box, null);
>
>        l.setBackgroundColor( getResources().getColor( R.color.red ) );
>
>        MarginLayoutParams params = new ViewGroup.MarginLayoutParams(50,
> 50);
>        params.setMargins(50, 70, 0, 0);
>        l.setLayoutParams( params );
>
>        containerView.addView( l );
>
> In result I got layout added but at left/top corner (0,0) not at (50,70).
> I also tried
>
>        containerView.addView( l, params );
>
> but no effect. Ideas?
>
> Regards,
> Marcin Orlowski
>
> *Tray Agenda <http://bit.ly/trayagenda>* - keep you daily schedule
> handy...
> *Date In Tray* <http://bit.ly/dateintraypro> - current date at glance...
> WebnetMobile on *Facebook <http://webnetmobile.com/fb/>*, 
> *Google+*<http://bit.ly/webnetmobile-gp>and
> *Twitter <http://webnetmobile.com/twitter/>*
>
>  --
> You received this message because you are subscribed to the Google
> Groups "Android Developers" group.
> To post to this group, send email to [email protected]
> To unsubscribe from this group, send email to
> [email protected]
> For more options, visit this group at
> http://groups.google.com/group/android-developers?hl=en

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to