滚动视图上方的线性布局

发布于 2024-12-21 09:52:47 字数 1191 浏览 5 评论 0原文

我有一个简单的 android 布局,由包含表格布局的滚动视图组成。该表显示正确,但我想在滚动视图上方添加一个静态标题,以便基本上表中列的标签始终保留在屏幕顶部。但是,当我在布局文件中的 上方添加 时,它会使其全部消失。

谁能发现我的 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 线性布局,它会显示得很好。

I've got a simple android layout consisting of a scrollview containing a tablelayout. 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.

Can anyone spot what I've done wrong with my xml file?

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

同尘 2024-12-28 09:52:48

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

Your scrollview's layout_height is set to fill_parent. Use wrap_content.

飞烟轻若梦 2024-12-28 09:52:47

LinearLayouts 需要具有 android:orientation参数设置。

LinearLayouts need to have the android:orientation parameter set.

筑梦 2024-12-28 09:52:47

您必须将父 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>

希望这有帮助!

You have to set the orientation of the parent LinearLayout to vertical! By default is set to horizontal that's way you don't see the 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!!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文