2011-12-16 63 views
2

我有一个简单的android布局,包含一个包含tablelayout的scrollview。这个表格显示正常,但我想在scrollview上添加一个静态标题,这样基本上表格中列的标签总是保持在屏幕的顶部。但是,当我在布局文件中的<ScrollView>之上添加<LinearLayout>时,它会使其全部消失。scrollview上面的线性布局

任何人都可以发现我的XML文件做错了吗?

<?xml version="1.0" encoding="utf-8"?> 

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
     android:id="@+id/linearLayout1" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:gravity="top" > 

     <LinearLayout 
      android:id="@+id/header" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      /> 

     <ScrollView 
      android:id="@+id/scrollView1" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" > 

      <TableLayout 
       android:id="@+id/mainTable" 
       android:layout_width="fill_parent" 
       android:layout_height="fill_parent" /> 
     </ScrollView> 

    </LinearLayout> 

正因为如此,我没有看到滚动视图或表格布局,但如果我删除了header的LinearLayout,它显示就好了。

+0

为什么没有设置任何[LinearLayouts](http://developer.android.com/resources/tutorials/views/hello-linearlayout.html)的方向? – Adinia 2011-12-16 19:47:47

+0

因为那正是我需要做的......使它成为答案,所以我可以接受它 – 2011-12-16 19:51:32

回答

1

您必须将父LinearLayout的方向设置为垂直!默认情况下设置为水平,这是你看不到ScrollView的方式。

,你可以试试这个:

<LinearLayout 
     android:id="@+id/header" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_weight="0" 
     /> 

    <ScrollView 
     android:id="@+id/scrollView1" 
     android:layout_width="fill_parent" 
     android:layout_height="0dp" android:layout_weight="1"> 

     <TableLayout 
      android:id="@+id/mainTable" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" /> 
    </ScrollView> 

希望这有助于!

+0

不幸的是,这并没有诀窍 – 2011-12-16 19:41:40

+0

检查更新的答案! – 2011-12-16 19:53:50

0

您的滚动视图的layout_height设置为fill_parent。使用wrap_content。