1

我正在尝试构建一个简单的表单,我想在顶部添加一个注释/标题/标题,以显示一条消息。我尝试过这样做,但文本已从屏幕上消失,并且其下方的内容也已被推开。我该如何反击?

这是我的layout.xml,它在 pastebin 上:http: //pastebin.com/fNBfQiz8

<TableLayout
   android:layout_width="match_parent"
   android:layout_height="wrap_content"
   android:shrinkColumns="1"
   android:stretchColumns="1" >

   <TableRow
       android:layout_marginBottom="2sp"
       android:layout_marginTop="2sp"
       android:layout_width="match_parent" >
        <TextView
           android:layout_width="match_parent"
           android:text="You can only add a spot based on your current location" />

    </TableRow>

   <TableRow
       android:layout_marginBottom="2sp"
       android:layout_marginTop="2sp" >
        <TextView android:text="Name:" />
        <EditText android:id="@+id/name" />
    </TableRow>

   <TableRow
       android:layout_marginBottom="2sp"
       android:layout_marginTop="2sp" >
        <TextView android:text="Address:" />
        <EditText android:id="@+id/addr" />
    </TableRow>

   <TableRow
       android:layout_marginBottom="2sp"
       android:layout_marginTop="2sp" >
        <TextView android:text="Type:" />
        <Spinner
           android:id="@+id/spinnerType"
           style="@style/AppBaseTheme"
           android:layout_width="wrap_content"
           android:layout_height="wrap_content"
           android:layout_weight="1"
           android:entries="@array/types_array"
           android:prompt="@string/types_prompt" />
    </TableRow>

   <TableRow
       android:layout_marginBottom="2sp"
       android:layout_marginTop="2sp" >
        <TextView android:text="Terrain:" />
        <Spinner
           android:id="@+id/spinnerTerrain"
           style="@style/AppBaseTheme"
           android:layout_width="wrap_content"
           android:layout_height="wrap_content"
           android:layout_weight="1"
           android:entries="@array/ratings_array"
           android:prompt="@string/ratings_prompt" />
    </TableRow>

    <TableRow>
        <TextView android:text="Difficulty:" />
        <Spinner
           android:id="@+id/spinnerDifficulty"
           style="@style/AppBaseTheme"
           android:layout_width="wrap_content"
           android:layout_height="wrap_content"
           android:layout_weight="1"
           android:entries="@array/ratings_array"
           android:prompt="@string/ratings_prompt" />
    </TableRow>

   <TableRow
       android:layout_marginBottom="2sp"
       android:layout_marginTop="2sp" >
        <TextView android:text="Description:" />
        <EditText
           android:id="@+id/desc"
           android:gravity="top"
           android:inputType="textMultiLine"
           android:lines="2"
           android:maxLines="2"
           android:scrollHorizontally="false" />
    </TableRow>

    <Button
       android:id="@+id/save"
       android:layout_width="match_parent"
       android:layout_height="wrap_content"
       android:text="Save"
                    android:layout_marginBottom="2sp"
       android:layout_marginTop="2sp" />
</TableLayout>

4

1 回答 1

0

我不确定我是否完全理解您在没有看到图片的情况下遇到的问题,但我查看了您的 pastebin。作为一般评论,布局中的根视图(在您的情况下为 ScrollView)可能应该具有match_parentfill_parent同时具有其宽度和高度,否则您可能会看到一些奇怪的渲染,您会看到没有布局覆盖屏幕的空白区域或得到一些奇怪的滚动行为。

这是一个很好的教程,它对 TableLayouts 中的列间距做了一些漂亮的事情,并且可以帮助你弄清楚为什么你的视图被截断并且不适合适当的空间。 请特别注意他在 TableRows 及其子项上使用了哪些属性,以实现他想要的布局。

至于您想要显示一些标题信息的问题,我可以想到两个选项。

  1. 如果您希望它们在 TableLayout 滚动时固定显示在屏幕顶部,请创建一个 LinearLayout 作为您的布局的根视图并将其方向设置为垂直。将您的标头作为第一个子项添加到此 LinearLayout,并将您的 ScrollView 作为第二个子项。
  2. 如果您希望标题信息与表格一起滚动,请将 ScrollView 作为您的根并创建一个 LinearLayout(同样具有垂直方向)作为它的唯一直接子级。将您的标题信息添加为 LinearLayout 的第一个子项,将 TableLayout 添加为第二个子项。

希望这可以帮助。如果您发布了您现在看到的屏幕截图以及您所针对的布局的某种类型的模型,它将有助于隔离您遇到的问题并帮助我们在社区中提供支持。

于 2013-03-06T22:39:06.120 回答