简体   繁体   English

滚动视图上方的线性布局

[英]Linear layout above a scrollview

I've got a simple android layout consisting of a scrollview containing a tablelayout. 我有一个简单的android布局,由包含tablelayout的scrollview组成。 This table displays properly, but I would like to add a static header above the scrollview, so that basically the labels for the columns in the table remain at the top of the screen always. 该表可以正确显示,但是我想在滚动视图上方添加一个静态标题,以便基本上该表中各列的标签始终保留在屏幕顶部。 However, when I add a <LinearLayout> above the <ScrollView> in my layout file, it makes it all disappear. 但是,当我在布局文件中的<ScrollView> <LinearLayout>上方添加<LinearLayout> ,它全部消失了。

Can anyone spot what I've done wrong with my xml file? 谁能发现我的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>

As it is, I do not see the scrollview or table layout, but if I remove the header linearlayout, it displays just fine. 照原样,我看不到scrollview或表的布局,但是如果删除header linearlayout,它会显示得很好。

LinearLayouts需要设置android:orientation参数。

You have to set the orientation of the parent LinearLayout to vertical! 您必须将父LinearLayout的方向设置为Vertical! By default is set to horizontal that's way you don't see the ScrollView. 默认情况下设置为水平,这样您就看不到ScrollView。

and you can try this: 您可以尝试以下操作:

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

Hope this helps!! 希望这可以帮助!!

Your scrollview's layout_height is set to fill_parent. 您的滚动视图的layout_height设置为fill_parent。 Use wrap_content. 使用wrap_content。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM