简体   繁体   中英

TableView in ScrollView does not appear

Why does not my second TableView appear? I want to create scroll-able TableView but I don't want to scroll my first row (it is a header) , so I thought to have 2 table views in vertical layout and the second table is in ScrollView , but my code does not work....

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <TableLayout
        android:id="@+id/main"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:shrinkColumns="0"
        android:stretchColumns="*" >

        <TableRow
            android:id="@+id/ww"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="#ffffff"
            android:padding="5dip" >

            <TextView
                android:id="@+id/w"
                android:layout_marginLeft="2dp"
                android:background="#000000"
                android:text="#"
                android:textAppearance="?android:attr/textAppearanceLarge" />

            <TextView
                android:id="@+id/aaa"
                android:layout_marginLeft="5dp"
                android:background="#000000"
                android:text="ID"
                android:textAppearance="?android:attr/textAppearanceLarge" />

            <TextView
                android:id="@+id/sss"
                android:layout_marginLeft="5dp"
                android:background="#000000"
                android:text="Initials"
                android:textAppearance="?android:attr/textAppearanceLarge" />

            <TextView
                android:id="@+id/ddd"
                android:layout_marginLeft="5dp"
                android:background="#000000"
                android:text="Last Session"
                android:textAppearance="?android:attr/textAppearanceLarge" />
        </TableRow>
    </TableLayout>

    <ScrollView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" >

        <TableLayout
            android:id="@+id/patientsTable"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:shrinkColumns="0"
            android:stretchColumns="*" >

            <TableRow
                android:id="@+id/pp"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:background="#ffffff"
                android:padding="5dip" >

                <TextView
                    android:id="@+id/uu"
                    android:layout_marginLeft="2dp"
                    android:background="#000000"
                    android:text="#"
                    android:textAppearance="?android:attr/textAppearanceLarge" />

                <TextView
                    android:id="@+id/uuu"
                    android:layout_marginLeft="5dp"
                    android:background="#000000"
                    android:text="ID"
                    android:textAppearance="?android:attr/textAppearanceLarge" />

                <TextView
                    android:id="@+id/uuuu"
                    android:layout_marginLeft="5dp"
                    android:background="#000000"
                    android:text="Initials"
                    android:textAppearance="?android:attr/textAppearanceLarge" />

                <TextView
                    android:id="@+id/yyy"
                    android:layout_marginLeft="5dp"
                    android:background="#000000"
                    android:text="Last Session"
                    android:textAppearance="?android:attr/textAppearanceLarge" />
            </TableRow>
        </TableLayout>
    </ScrollView>

</LinearLayout>

I think it's because you set the first Table's height to fill_parent . Try to change it to wrap_content . If this does not work, you can also change your parent container as follows:

<RelativeLayout 
     ... >
     <TableLayout
         android:id="@+id/first_table"
         android:layout_alignParentTop="true"
         android:layout_width="fill_parent"
         android:layout_height="wrap_content"
         ... >
     </TableLayout>
     <ScrollView
         android:layout_below="@id/first_table"
         android:layout_width="fill_parent"
         android:layout_height="wrap_content"
         ... >
     </ScrollView>
</RelativeLayout>

Just play with weights.

<TableLayout
    android:id="@+id/main"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:shrinkColumns="0"
    android:stretchColumns="*" >

    <TableRow
        android:id="@+id/ww"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="#ffffff"
        android:padding="5dip" >

        <TextView
            android:id="@+id/w"
            android:layout_marginLeft="2dp"
            android:background="#000000"
            android:text="#"
            android:textAppearance="?android:attr/textAppearanceLarge" />

        <TextView
            android:id="@+id/aaa"
            android:layout_marginLeft="5dp"
            android:background="#000000"
            android:text="ID"
            android:textAppearance="?android:attr/textAppearanceLarge" />

        <TextView
            android:id="@+id/sss"
            android:layout_marginLeft="5dp"
            android:background="#000000"
            android:text="Initials"
            android:textAppearance="?android:attr/textAppearanceLarge" />

        <TextView
            android:id="@+id/ddd"
            android:layout_marginLeft="5dp"
            android:background="#000000"
            android:text="Last Session"
            android:textAppearance="?android:attr/textAppearanceLarge" />
    </TableRow>
</TableLayout>

<ScrollView
    android:layout_height="0dp"
    android:layout_weight="1"
    android:layout_width="fill_parent" >

    <TableLayout
        android:id="@+id/patientsTable"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:shrinkColumns="0"
        android:stretchColumns="*" >

        <TableRow
            android:id="@+id/pp"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="#ffffff"
            android:padding="5dip" >

            <TextView
                android:id="@+id/uu"
                android:layout_marginLeft="2dp"
                android:background="#000000"
                android:text="#"
                android:textAppearance="?android:attr/textAppearanceLarge" />

            <TextView
                android:id="@+id/uuu"
                android:layout_marginLeft="5dp"
                android:background="#000000"
                android:text="ID"
                android:textAppearance="?android:attr/textAppearanceLarge" />

            <TextView
                android:id="@+id/uuuu"
                android:layout_marginLeft="5dp"
                android:background="#000000"
                android:text="Initials"
                android:textAppearance="?android:attr/textAppearanceLarge" />

            <TextView
                android:id="@+id/yyy"
                android:layout_marginLeft="5dp"
                android:background="#000000"
                android:text="Last Session"
                android:textAppearance="?android:attr/textAppearanceLarge" />
        </TableRow>
    </TableLayout>
</ScrollView>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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