Android 滚动视图上方的线性布局

Android 滚动视图上方的线性布局,android,scrollview,android-linearlayout,Android,Scrollview,Android Linearlayout,我有一个简单的android布局,由一个包含tablelayout的滚动视图组成。此表显示正确,但我想在scrollview上方添加一个静态标题,这样表中列的标签基本上始终保持在屏幕顶部。但是,当我在布局文件中的上方添加时,它会使它全部消失 有人能发现我对xml文件做了什么错误吗 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/

我有一个简单的android布局,由一个包含tablelayout的滚动视图组成。此表显示正确,但我想在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>


实际上,我看不到滚动视图或表格布局,但如果我删除
标题
linearlayout,它显示得很好。

您必须将父linearlayout的方向设置为垂直!默认情况下设置为水平,这是您看不到滚动视图的方式

你可以试试这个:

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


希望这有帮助

您的scrollview的布局高度设置为填充父视图。使用包裹内容。

需要设置
android:orientation
参数。

还可以将包裹内容用于表格布局的高度。我想这是我的答案,但显然不是。你为什么不为你的任何一个页面设置方向?因为这正是我需要做的…让它成为我可以接受的答案。是的,出于某种原因,这就是问题所在,我将主布局设置为具有
垂直
方向,和内部的一个有一个水平方向。现在我只需要弄清楚为什么内部布局占用了比需要更多的垂直空间…可能是因为主布局和滚动都设置为
fill\u parent
。。!?嗯,是滚动视图(设置为
fill\u parent
)没有占用足够的空间。出于某种原因,当我在内部
LinearLayout
的某些子视图中设置文本时,它会导致文本展开过多