Search code examples
javaandroidlayoutscrollviewpixel

How do I remove the extra pixels at the top of a ScrollView?


I have been working on an app that allows you to create a Truth Table and save it into HTML for use in word. I have the app working fine but I am trying to clean it up a bit. I have the following layout code to allow you to scroll the table while still keeping the name row at the top:

    <RelativeLayout
        android:id="@+id/RelLayout"
        android:layout_width="wrap_content"
        android:layout_height="fill_parent" >

        <TableLayout
            android:id="@+id/nameTable"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_margin="1dp" >

            <TableRow
                android:id="@+id/nameRow"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" />
        </TableLayout>

        <ScrollView
            android:id="@+id/scrollView1"
            android:layout_width="wrap_content"
            android:layout_height="fill_parent"
            android:scrollbarStyle="insideOverlay"
            android:scrollbars="vertical" >

            <TableLayout
                android:id="@+id/TruthTableLayout"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_margin="1dp"
                android:background="#000000" >
            </TableLayout>
        </ScrollView>
    </RelativeLayout>
</HorizontalScrollView>

This works fine for me overall, but when I scroll the table it doesn't fade immediately and instead shows a few pixels above the name row. So my question is how can I make those pixels go away?

Because I don't have the reputation to post images, here is a link to a screenshot of what I'm talking about. https://i.sstatic.net/dGQcf.png


Solution

  • For starters your margin here:

       <TableLayout
            android:id="@+id/nameTable"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_margin="1dp" >
    

    should be 0 on the top. SO if you need side margins it should be:

       <TableLayout
            android:id="@+id/nameTable"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginRight="1dp"
            android:layout_marginLeft="1dp" >