Sorry about the previous post. Your code looks ok.
On closer look your  LinearLayout "attr_list" is  oriented
horizontally (by default) with width/height set to "fill_parent".
Change to  android:orientation="vertical" and you will have the
children shown up properly.

Another tip would be to use "include" tag to reduce the layout
complexity.
Check out the following blogpost :
http://android-developers.blogspot.com/2009/02/android-layout-tricks-2-reusing-layouts.html


On Dec 17, 9:12 am, Chander Pechetty <[email protected]> wrote:
> This hopefully should work,
>
> LayoutInflater layoutInflater = LayoutInflater.from(getBaseContext());
> (or get it as a Service)
> View childView = layoutInflater.inflate(R.layout.child_item, null);
> group.addView(childView); ( // add it to any ViewGroup)
>
> -Chander
>
> On Dec 16, 11:09 pm, Ben Griffiths <[email protected]>
> wrote:
>
> > Okay, so I've got down the LinearLayout in a ScrollView way and I seem
> > to have hacked something together... But, it doesn't quite work.
>
> > It does something - see the linked pictures
>
> > Hierarchy:
> > Beforehttp://tinyurl.com/ybl7f8j
> > Afterhttp://tinyurl.com/ybohtyv
>
> > App:
> > Beforehttp://tinyurl.com/yblw2mp
> > Afterhttp://tinyurl.com/ycjfoya
>
> > As you can see, it seems to add it but not display it. Clicking on my
> > add button adds as many as I want according the hierarchy viewer, but
> > the buttons only move to accommodate them once.
>
> > It was guess work that got me this far, so I'm not entirely sure if
> > I'm using methods correctly here. But the main xml layout is:
>
> > <?xml version="1.0" encoding="utf-8"?>
> > <ScrollView
> >   xmlns:android="http://schemas.android.com/apk/res/android";
> >   android:orientation="vertical"
> >   android:layout_width="fill_parent"
> >   android:layout_height="fill_parent">
> >   <LinearLayout
> >     android:id="@+id/edit_options"
> >     android:orientation="vertical"
> >     android:layout_width="fill_parent"
> >     android:layout_height="fill_parent">
> >     <LinearLayout
> >      android:layout_width="fill_parent"
> >      android:layout_height="fill_parent">
> >       <TextView
> >         android:text="@string/edit_offer1"
> >         android:layout_width="wrap_content"
> >         android:layout_height="fill_parent"
> >         android:gravity="center_vertical" />
> >       <EditText
> >         android:id="@+id/product_name"
> >         android:layout_width="fill_parent"
> >         android:layout_height="wrap_content"
> >         android:inputType="textPersonName" />
> >     </LinearLayout>
> >     <View
> >       android:background="@android:drawable/divider_horizontal_bright"
> >       android:layout_width="fill_parent"
> >       android:layout_height="wrap_content" />
> >     <LinearLayout
> >       android:layout_width="fill_parent"
> >       android:layout_height="wrap_content"
> >       android:layout_marginTop="5dip">
> >       <TextView
> >         android:text="@string/edit_subtitle"
> >         android:layout_width="fill_parent"
> >         android:layout_height="fill_parent"
> >         android:layout_weight="1"
> >         android:gravity="center_vertical" />
> >       <ImageButton
> >         android:id="@+id/add_attr"
> >         android:layout_width="wrap_content"
> >         android:layout_height="wrap_content"
> >         android:background="@drawable/btn_add_states">
> >       </ImageButton>
> >     </LinearLayout>
> >     <LinearLayout
> >       android:id="@+id/attr_list"
> >       android:layout_width="fill_parent"
> >       android:layout_height="fill_parent">
> >       <LinearLayout
> >         android:id="@+id/attr_row_default"
> >         android:layout_width="fill_parent"
> >         android:layout_height="wrap_content">
> >         <EditText
> >           android:hint="Attribute"
> >           android:layout_width="0dip"
> >           android:layout_weight="2"
> >           android:layout_height="wrap_content"
> >           android:inputType="textPersonName" />
> >         <EditText
> >           android:hint="Value"
> >           android:layout_width="0dip"
> >           android:layout_weight="3"
> >           android:layout_height="wrap_content"
> >           android:inputType="textPersonName" />
> >         <ImageButton
> >           android:id="@+id/drop_attr"
> >           android:layout_width="wrap_content"
> >           android:layout_height="wrap_content"
> >           android:background="@drawable/btn_delete_states"
> >           android:layout_gravity="center_vertical" />
> >       </LinearLayout>
> >     </LinearLayout>
> >     <LinearLayout
> >       android:layout_width="fill_parent"
> >       android:layout_height="wrap_content"
> >       android:layout_gravity="bottom">
> >       <Button
> >           android:id="@+id/btn_done"
> >           android:text="@string/ok"
> >           android:layout_width="0dip"
> >           android:layout_weight="1"
> >           android:layout_height="wrap_content"
> >           />
> >         <Button
> >           android:id="@+id/btn_discard"
> >           android:text="@string/discard"
> >           android:layout_width="0dip"
> >           android:layout_weight="1"
> >           android:layout_height="wrap_content" />
> >     </LinearLayout>
> >   </LinearLayout>
>
> > </ScrollView>
>
> > Each extra row has the following xml:
>
> > <?xml version="1.0" encoding="utf-8"?>
> > <LinearLayout
> >   xmlns:android="http://schemas.android.com/apk/res/android";
> >   android:id="@+id/attr_row"
> >   android:layout_width="fill_parent"
> >   android:layout_height="wrap_content">
> >   <EditText
> >     android:hint="Attribute"
> >     android:layout_width="0dip"
> >     android:layout_weight="2"
> >     android:layout_height="wrap_content"
> >     android:inputType="textPersonName" />
> >   <EditText
> >     android:hint="Value"
> >     android:layout_width="0dip"
> >     android:layout_weight="3"
> >     android:layout_height="wrap_content"
> >     android:inputType="textPersonName" />
> >   <ImageButton
> >     android:id="@+id/drop_attr"
> >     android:layout_width="wrap_content"
> >     android:layout_height="wrap_content"
> >     android:background="@drawable/btn_delete_states"
> >     android:layout_gravity="center_vertical" />
> > </LinearLayout>
>
> > The code tied to the imageButton with a Listener is
>
> > LinearLayout attrList = (LinearLayout) findViewById(R.id.attr_list);
> > LinearLayout extraAttr = (LinearLayout) LinearLayout.inflate
> > (v.getContext(),
> >                                               R.layout.attr_row,
> >                                               null);
> > attrList.addView(extraAttr);
>
> > In particular, I'm guessing I'm not using inflate correctly..

-- 
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