2013-03-06 49 views
1

我正在尝试构建一个简单的表单,并且想在显示消息的顶部添加一个注释/标题/标题。我试图做到这一点,但文本已经离开了屏幕,下面的东西也被推掉了。我该如何解决这个问题?如何解决不适合屏幕的TextView问题,并将其他内容从屏幕上移开?

这是我layout.xml,在这里它是在引擎收录: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> 

+0

你有把'android:layout_height =“wrap_content”'和'android:layout_width =“wrap_content”'。一个可能有用的想法... – TronicZomB 2013-03-06 22:00:10

+0

嗨,谢谢。是的,我把它放在TextView和封装的TableRow中。它解决了屏幕问题的文本,但其他小部件仍然消失。 – 2013-03-06 22:03:31

+0

这很好,也许尝试将这两行添加到每个“TextView”,“EditText”,“Spinner”和“Button”标记中。我不认为你需要'TableRow',但不能确定。我对Android还是比较陌生,但我认为每个可见的组件都必须具备这两个属性,但我不能100%确定。 – TronicZomB 2013-03-06 22:34:22

回答

0

我不知道我完全理解问题,您遇到什么,没有看到一个画面,但我看了看你的pastebin。作为一般性评论,布局中的根视图(对于您的情况,ScrollView)的宽度和高度可能应该有match_parentfill_parent,否则您可能会看到一些奇怪的呈现,您会看到空白区域,其中没有布局覆盖屏幕或获得一些奇怪的滚动行为。

Here is a good tutorial which does nifty things with the spacing of the columns in TableLayouts and may help you figure out why your views are getting cut off and otherwise not fitting into the proper space.请特别注意他在他的TableRows和他们的孩子上使用哪些属性以实现他想要的布局。

至于你想要显示一些头信息的问题,我可以考虑两个选项。

  1. 如果你希望它们出现固定在屏幕的顶部,而TableLayout卷轴,创建一个LinearLayout中充当你的布局根视图,并设置其方向垂直。将您的标题作为第一个孩子添加到此LinearLayout,将您的标题添加到第二个孩子。
  2. 如果您希望标题信息随表格一起滚动,请将ScrollView作为您的根,并创建一个LinearLayout(再次以垂直方向)作为它的唯一直接子对象。将您的标题信息添加为LinearLayout的第一个子元素,将TableLayout添加为第二个子元素信息。

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