Question

I want both the ScrollView TableLayout to have same height as the screen, but whyy table is taken only half of the screen, whereas ScrollView is taking full screen as intended.

I tried changing height of table and rows as wrap_content, but showing same result. Also changing height of table as fixed height (e.g. 900dp) is not working as well. Even the last row height is not showing full rating bar. Seems like table is forced to have that specific width.

If I delete ScrollView, it works just fine.

Can anyone please help.

<ScrollView 
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:background="@drawable/border"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".EditEntry" >
    <TableLayout
        android:id="@+id/tableLayout1"
        android:layout_width="match_parent"
        android:layout_height="match_parent" >

        <TableRow
            android:id="@+id/tr3a"
            android:padding="2.5dp"
            android:background="@color/col1"
            android:gravity="center_vertical"
            android:layout_width="wrap_content"
            android:layout_height="0dp"
        android:layout_weight="1" >

            <TextView
                android:id="@+id/lab_bookname"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/bookname" />

            <EditText
                android:id="@+id/bookname"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:hint="@string/definputtext2" />

        </TableRow>

        <TableRow
            android:id="@+id/tr3"
            android:padding="2.5dp"
            android:background="@color/col2"
            android:gravity="center_vertical"
            android:layout_width="wrap_content"
            android:layout_height="0dp"
        android:layout_weight="1" >
            <TextView
                android:id="@+id/lab_printname"
            android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/print_name" />

            <EditText
                android:id="@+id/printname"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:hint="@string/definputtext2" />

        </TableRow>
        ......................
        ......................
        ......................
    </TableLayout>
</ScrollView>

enter image description here

Was it helpful?

Solution

add this line in your scrollview xml -->

     android:fillViewport="true"

This enables the child layout to to take full screen if it's layout_width & layout_height is match_parent/fill_parent. . In your case TableLayout will get the full size on using this line ..! enjoy...!

OTHER TIPS

Putting a linearlayout in between works but I don't know why setting some height to table view directly doesn't work.

   <ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@android:color/black"
        android:paddingBottom="@dimen/activity_vertical_margin"
        android:paddingLeft="@dimen/activity_horizontal_margin"
        android:paddingRight="@dimen/activity_horizontal_margin"
        android:paddingTop="@dimen/activity_vertical_margin"
        tools:context=".EditEntry" >

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@android:color/darker_gray" >

            <TableLayout
                android:id="@+id/tableLayout1"
                android:layout_width="match_parent"
                android:layout_height="1000dp" >

                <TableRow
                    android:id="@+id/tr3a"
                    android:layout_width="wrap_content"
                    android:layout_height="0dp"
                    android:layout_weight="1"
                    android:background="@color/col1"
                    android:gravity="center_vertical"
                    android:padding="2.5dp" >

                    <TextView
                        android:id="@+id/lab_bookname"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:text="@string/bookname" />

                    <EditText
                        android:id="@+id/bookname"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:hint="@string/definputtext2" />
                </TableRow>

                <TableRow
                    android:id="@+id/tr3"
                    android:layout_width="wrap_content"
                    android:layout_height="0dp"
                    android:layout_weight="1"
                    android:background="@color/col2"
                    android:gravity="center_vertical"
                    android:padding="2.5dp" >

                    <TextView
                        android:id="@+id/lab_printname"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:text="@string/print_name" />

                    <EditText
                        android:id="@+id/printname"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:hint="@string/definputtext2" />
                </TableRow>
            </TableLayout>
        </LinearLayout>

    </ScrollView>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top