Thanks Dan, It worked.

It wud be much better if i can do this thru xml, Can u share your XML
Layout for this?

Regards,

Dan U. wrote:
> Your code works fine for me. Do you have more information about the
> crash? Is there a stack trace? I did change it a bit to let me test
> with an xml layout (I tested both with xml layout and
> programmatically):
>
> class ViewLayout extends LinearLayout {
>
>       public ViewLayout(Context context, AttributeSet attrs, Map
> inflateParams) {
>               super(context, attrs, inflateParams);
>               init(context);
>       }
>
>       public ViewLayout(Context context) {
>               super(context);
>               init(context);
>       }
>
>       private void init(Context context) {
>               try {
>                       RelativeLayout rel = new RelativeLayout(context);
>
>                       RelativeLayout.LayoutParams relLayout = new
> RelativeLayout.LayoutParams(
>                                       LayoutParams.WRAP_CONTENT, 
> LayoutParams.WRAP_CONTENT);
>                       relLayout.addRule(RelativeLayout.ALIGN_WITH_PARENT_TOP);
>                       
> relLayout.addRule(RelativeLayout.ALIGN_WITH_PARENT_LEFT);
>
>                       addView(rel, new LinearLayout.LayoutParams(
>                                       LayoutParams.FILL_PARENT, 
> LayoutParams.WRAP_CONTENT));
>               } catch (Exception e) {
>               }
>       }
> }
>
> On May 4, 10:44 am, dreamer <[EMAIL PROTECTED]> wrote:
> > I want to add a relativelayout in linearlayout in my code: My code is:
> >
> > class ViewLayout extends LinearLayout {
> >
> >   ViewLayout(Context context)
> >   {
> >      ......
> >     try{
> >      RelativeLayout rel = new RelativeLayout(context);   // create rel
> > layout
> >
> >      RelativeLayout.LayoutParams relLayout = new
> > RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
> > LayoutParams.WRAP_CONTENT);
> >         relLayout.addRule(RelativeLayout.ALIGN_WITH_PARENT_TOP);
> >         relLayout.addRule(RelativeLayout.ALIGN_WITH_PARENT_LEFT);
> >
> >        addView(rel, new
> > LinearLayout.LayoutParams(LayoutParams.FILL_PARENT,
> > LayoutParams.WRAP_CONTENT));
> >         }
> >         catch(Exception e)
> >          {
> >          }
> >   }
> >
> > }
> >
> > The addView line crashes. Does anybody know how to add RelLayout in
> > LinearLayout?
--~--~---------~--~----~------------~-------~--~----~
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]
Announcing the new M5 SDK!
http://android-developers.blogspot.com/2008/02/android-sdk-m5-rc14-now-available.html
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to