abdfahim
abdfahim

Reputation: 2553

Android TableLayout inside ScrollView

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

Upvotes: 3

Views: 19478

Answers (2)

vipul mittal
vipul mittal

Reputation: 17401

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>

Upvotes: 2

Kailash Dabhi
Kailash Dabhi

Reputation: 3513

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

Upvotes: 11

Related Questions