簡體   English   中英

滾動視圖上方的線性布局

[英]Linear layout above a scrollview

我有一個簡單的android布局,由包含tablelayout的scrollview組成。 該表可以正確顯示,但是我想在滾動視圖上方添加一個靜態標題,以便基本上該表中各列的標簽始終保留在屏幕頂部。 但是,當我在布局文件中的<ScrollView> <LinearLayout>上方添加<LinearLayout> ,它全部消失了。

誰能發現我的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>

照原樣,我看不到scrollview或表的布局,但是如果刪除header linearlayout,它會顯示得很好。

LinearLayouts需要設置android:orientation參數。

您必須將父LinearLayout的方向設置為Vertical! 默認情況下設置為水平,這樣您就看不到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>

希望這可以幫助!!

您的滾動視圖的layout_height設置為fill_parent。 使用wrap_content。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM