java - 如何删除 ScrollView 顶部的多余像素?

标签 java android layout scrollview pixel

我一直在开发一款允许您创建真值表并将其保存到 HTML 中以便在 word 中使用的应用程序。我的应用程序运行良好,但我正在尝试对其进行一些清理。我有以下布局代码,可让您滚动表格,同时仍将名称行保持在顶部:

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

这对我来说总体上很好,但是当我滚动表格时它不会立即消失,而是在名称行上方显示几个像素。所以我的问题是如何让这些像素消失?

因为我没有发布图片的声誉,所以这里有一个链接,指向我正在谈论的内容的屏幕截图。 http://i.imgur.com/4KWc32O.png

最佳答案

首先,您的 margin 在这里:

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

在顶部应该是0。所以如果你需要侧边距,它应该是:

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

关于java - 如何删除 ScrollView 顶部的多余像素?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16533839/

相关文章:

使用 longs 的 HashSet 的 Java 代码不起作用?

java - Glassfish 4.0 中的 DigestRealmBase 发生了什么?

java - 为什么 A* 寻路有时走直线有时走对角线? ( java )

android - 如何在 Android 应用程序中使用 OpenCV 以纵向模式打开相机

android - 更新到 Android Studio 2.2/gradle 插件 2.2.0 : "could not get unknown property ' assembleRelease'"后

java - 如何在 JPanel 中保持宽高比

java - 如何将字符串转换为 JSONArray?

java - 同步调整 jPanel 组件的大小

html - 更改 CSS 字体大小会改变其他 -em 设置吗?

html - 流体布局中的页脚实现