【问题标题】:ScrollView cutting off part of the layoutScrollView 截断部分布局
【发布时间】:2013-11-03 19:11:34
【问题描述】:

我的布局中的ScrollView 有一个奇怪的问题,即它切断了TableLayout 的底部。 这是它的样子when scrolling to the top.

带有圆角的绿色背景应该与底部相同,即它实际上只是一个可绘制圆角的普通矩形。但是当我尝试滚动到底部时,here's what I see:

如您所见,底角是不可见的,我无法再滚动。现在,我只看到评论部分的所有行,因为我手动添加了一些 android:paddingBottomTableLayout(见下文),否则更多会被切断。我就是想不通,问题是什么。 有人可以告诉我我错过了什么吗?这是 XML 布局。它由运行时的数据库查询填充。

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

    <TableLayout
        android:id="@+id/table"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_margin="30dp"
        android:background="@drawable/some_shape"
        android:paddingBottom="40dp" >

        <TableRow android:layout_margin="20dp" >

            <TextView
                android:id="@+id/code_label"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginRight="20dp"
                android:text="Code:" />

            <TextView
                android:id="@+id/code_field"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="test" />
        </TableRow>

        <TableRow android:layout_margin="20dp" >

            <TextView
                android:id="@+id/name_label"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginRight="20dp"
                android:text="Name:" />

            <TextView
                android:id="@+id/name_field"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="test" />
        </TableRow>

        <TableRow android:layout_margin="20dp" >

            <TextView
                android:id="@+id/pra_label"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginRight="20dp"
                android:text="Type:" />

            <TextView
                android:id="@+id/pra_field"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="test" />
        </TableRow>

        <TableRow android:layout_margin="20dp" >

            <TextView
                android:id="@+id/day_label"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginRight="20dp"
                android:text="Day:" />

            <TextView
                android:id="@+id/day_field"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="test" />
        </TableRow>

        <TableRow android:layout_margin="20dp" >

            <TextView
                android:id="@+id/room_label"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginRight="20dp"
                android:text="Room:" />

            <TextView
                android:id="@+id/room_field"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="test" />
        </TableRow>

        <TableRow android:layout_margin="20dp" >

            <TextView
                android:id="@+id/time_label"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginRight="20dp"
                android:text="Time:" />

            <LinearLayout android:orientation="horizontal" >

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

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="10dp"
                    android:layout_marginRight="10dp"
                    android:text="@string/to" />

                <TextView
                    android:id="@+id/time_field2"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="test2" />
            </LinearLayout>
        </TableRow>

        <TableRow android:layout_margin="20dp" >

            <TextView
                android:id="@+id/comment_label"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginRight="20dp"
                android:text="Comments:" />

            <TextView
                android:id="@+id/comment_field"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="test" />
        </TableRow>
    </TableLayout>

</ScrollView>

【问题讨论】:

  • 将 fillviewport 添加到您的滚动视图中
  • @Mikel:完成。没有效果。
  • 是的,对不起我的错误,这适用于相反的情况,当您不占用所有屏幕并希望滚动填满所有屏幕时。
  • 您找到解决方案了吗?我也有同样的问题。

标签: android layout scrollview


【解决方案1】:

我知道为时已晚,但答案是从 TableLayout 中删除 android:layout_margin="30dp"

【讨论】:

  • 是的,我所要做的就是从子对象中删除边距,谢谢!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-11-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多