Thursday, August 18, 2011

[android-developers] Re: Place a custom view on a relative layout programmatically

>         MyCustomView customView = new MyCustomView(this);
>         // Settings here the margin : Doesn't works!
>         MarginLayoutParams mLayoutParams = new MarginLayoutParams(338,
> 338);
>         mLayoutParams.setMargins(100, 100, 0, 0);
>         customView.setLayoutParams(mLayoutParams);
>         mainLayout.addView(customView, 0, mLayoutParams);

Replace with the following codes and you will find the custom view on
the right position:

// for testing only
MyCustomView customView = new MyCustomView(this);
RelativeLayout.LayoutParams layoutParam = new
RelativeLayout.LayoutParams(100, 100);
layoutParam.setMargins(100, 100, 0, 0);
mainLayout.addView(customView, 0, layoutParam);

BTW, for specified width and height of this custom view, you need to
check the View.onMeasure() method.

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

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate