1

I'm working on an App, which contains a Table Layout in a Scrollview. I want the Table to fill the width of the screen, but I don't really now what to do.

I tried to first set the scrollView to fill_parent, but then I get dozens of "unhandled event loop exceptions". And about three "Invalid preference page path: XML Syntax" Errors.

If I just try to set the table layout to fill_parent just nothing happens. Here is an excerpt of my "scroll-table construction"

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >

<LinearLayout
    android:id="@+id/linearLayout1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" >

    <Button
        android:id="@+id/btnNew"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="0.20"
        android:text="New" />

    <Button
        android:id="@+id/btnDelete"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="0.20"
        android:text="Delete" />
</LinearLayout>


<ScrollView
    android:id="@+id/scrollView1"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:layout_weight="0.20" >

    <TableLayout
        android:id="@+id/tableLayout1"
        android:layout_width="match_parent"
        android:layout_height="match_parent" >

        <TableRow
            android:id="@+id/tableRow1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" >

            <TextView
                android:id="@+id/textView1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:background="@drawable/cell_shape2"
                android:padding="5dp"
                android:textAppearance="?android:attr/textAppearanceSmall" />

... etc. (much stuff not necessary).

I hope you can give me a hint, because I really don't know why my scrollview can't fit the parent width and I don't know, if it would help, if it would fit.

1 Answer 1

7

If you're using Eclipse, try to use menu Project -> Clean... -> (select your project) -> Press OK. This is sometimes needed to recompile the xml resources when you've changed something.

Also, I don't think you can have a both a LinearLayout and a ScrollView in the root of an XML-layout.

If you'd like the columns content to fill you probably need to set

android:stretchColumns="1"

on the TableLayout, and

android:layout_column="1"

on the TextView.

You could also try and use

android:fillViewport="true"

on the ScrollView.

3
  • Okay thanks, the error is gone, but if i set both elements to match_parent the Table is still just as big as the text in columns.
    – mkay
    Dec 5, 2011 at 10:31
  • thanks, the stretchColumns worked ! I thought i have to use match_parant... anyway Problem solfed and thank you very much! i really would like to vote your answer up... damn reputation...
    – mkay
    Dec 5, 2011 at 11:43
  • I also found that setting a Weight of 1 on my table fixed it.
    – Chris Rae
    Nov 26, 2013 at 20:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.