1

I know I'm close but i just need a little help in inflating my layout.

I have a LinearLayout, containing a ScrollView and a HorizontalScrollView, the ScrollView contains a second LinearLayout which contains a TextView and an ImageView and the HorizontalScrollView contatins a third LinearLayout containing a TextView.

Here's the XML:

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/mainLinearLayout"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

    <ScrollView
        android:id="@+id/scroll1"
        android:layout_width="fill_parent"
        android:layout_height="442dp"
        android:layout_weight="1" >

        <LinearLayout
            android:id="@+id/contentLayout"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical" >

            <TextView
                android:id="@+id/contentText"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="TextView" />

            <ImageView 
                android:id="@+id/image_content"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center" />

        </LinearLayout>
    </ScrollView>

    <HorizontalScrollView
        android:id="@+id/horizontalScrollView1"
         android:layout_width="fill_parent"
        android:layout_height="25dp"
        android:layout_gravity="bottom">"

    <LinearLayout
        android:id="@+id/footerLayout"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_gravity="bottom"
        android:orientation="horizontal" >

        <TextView
            android:id="@+id/footer"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_gravity="bottom"
            android:paddingLeft="5dp"
            android:paddingRight="5dp" />

    </LinearLayout>
</HorizontalScrollView>
</LinearLayout>

The issue I am having is twofold.

  1. The HorizontalScrollView should be at the bottom, instead it is slightly up, I am guessing due to the height dimensions on the ScrollView (This should take up all the space except for the 25dp reserved by the HorizontalScrollView.

  2. I am having issues inflating the LinearLayouts within the ScrollViews I currently have the code:

    LayoutInflater inflater = (LayoutInflater)
        getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    LinearLayout layoutContent;
    LinearLayout lin = new LinearLayout(this);
    TextView content = null;
    
    //Content
    for (int i =0; i<6; i++) {
        layoutContent = (LinearLayout)inflater.inflate(R.layout.details_list, null);
        content = (TextView)layoutContent.findViewById(R.id.contentText);
        content.setText("MyContent" + String.valueOf(i));
        lin.addView(layoutContent);
    }
    this.setContentView(lin);
    
    //Footer
    lin = (LinearLayout) findViewById(R.id.footerLayout);
    content = null;
    for (int i =0; i<2; i++) {
        layoutContent = (LinearLayout)inflater.inflate(R.layout.details_list, null);
        content = (TextView)layoutContent.findViewById(R.id.footer);
        content.setText("Footer "+String.valueOf(i));
        lin.addView(layoutContent);
    }
    

which causes me problems: As the content layout is declared as lin = new LinearLayout(this); this is not using the one from my layout file e.g. the layout looks like

MyContent0             MyContent1MyContent2MyC
                                          onte
                                          nt3

  Footer 0    Footer 1

If i increase the number of footer items the MyContent1... appears to get pushed off the right of the screen, if I change it to lin = (LinearLayout) findViewById(R.id.contentLayout); I must remove the line this.setContentView(lin); but when i do that the layout looks like:

TextView
MyContent0
--Lots of blank lines--
  Footer 0   Footer 1
MyContent1
--Lots of blank lines--
MyContent2
--Lots of blank lines--
MyContent3
--Lots of blank lines--
MyContent4
--Lots of blank lines--
MyContent5
--Lots of blank lines--

If add more elements to the footer, these appear in a HorizontalScroll where Footer 1 Footer 2 is above and scrolls correctly with the rest of the content below.

Many Thanks for taking the time to read this and please let me know if you require more information.

Kind Regards

Kiran
  • 20,167
  • 11
  • 67
  • 99
Alasdair
  • 566
  • 1
  • 4
  • 16
  • 1/ use fill_parent instead of 442dp – njzk2 Mar 20 '12 at 15:05
  • 1
    2/ you are not using properly the xml layout you defined. you probably want to set it as content view, then findViewById(R.id.contentLayout) before adding rows to it – njzk2 Mar 20 '12 at 15:07
  • + new LinearLayout is horizontal. also, you are adding 6 scrollviews to your lin. that is not correct either. – njzk2 Mar 20 '12 at 15:08
  • each time you inflate details_list, you actually create a whole new tree of views as declared in your xml file – njzk2 Mar 20 '12 at 15:09
  • So if i get what you are saying I should remove the TextViews from the layout, put these into a Content and Footer layout xml with only the TextView in it and inflate that? – Alasdair Mar 20 '12 at 15:46

0 Answers0