ScrollView with RelativeLayout

93 views Asked by At

I have implemented a LinearGraph and add in the LinearLayout (in xml that is LinearLayout with id="linearLayout1").

Now I want to add table after this chart and I need to use ScrollView cause table will have more then one row.

Here is one of my xml that i tried but no success...

    <ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fillViewport="true"
        android:orientation="vertical" >


        <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
            android:layout_width="match_parent"
            android:layout_height="match_parent" >

                    <LinearLayout
                        android:layout_height="wrap_content"
                        android:layout_width="wrap_content"
                        android:paddingLeft="@dimen/activity_horizontal_margin"
                        android:paddingRight="@dimen/activity_horizontal_margin"
                        android:paddingTop="@dimen/activity_vertical_margin"
                        android:paddingBottom="@dimen/activity_vertical_margin"
                        android:id="@+id/linearLayout1"
                        android:orientation="vertical"
                        android:layout_above="@+id/tableLayout">
                    </LinearLayout>


                    <TableLayout
                        android:id="@+id/tableLayout"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:background="@drawable/my_drawable"
                        android:padding="5dp"
                        android:layout_alignParentBottom="true"
                        >

                        <TableRow
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content" >

                            <TextView
                                android:id="@+id/home"
                                android:layout_width="0dp"
                                android:layout_weight="1"
                                android:background="@drawable/my_drawable"
                                android:gravity="center"
                                android:padding="15dip"
                                android:text="Months" />

                            <TextView
                                android:id="@+id/status"
                                android:layout_width="0dp"
                                android:layout_weight="1"
                                android:background="@drawable/my_drawable"
                                android:gravity="center"
                                android:padding="15dip"
                                android:text="Number of Visits" />
                        </TableRow>

                        <TableRow
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content" >

                            <TextView
                                android:layout_width="0dp"
                                android:layout_weight="1"
                                android:background="@drawable/my_drawable"
                                android:gravity="center"
                                android:padding="15dip"
                                android:text="January" />

                            <TextView
                                android:layout_width="0dp"
                                android:layout_weight="1"
                                android:background="@drawable/my_drawable"
                                android:gravity="center"
                                android:padding="15dip"
                                android:text="1" />
                        </TableRow>

                        <TableRow
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content" >

                            <TextView
                                android:layout_width="0dp"
                                android:layout_weight="1"
                                android:background="@drawable/my_drawable"
                                android:gravity="center"
                                android:padding="15dip"
                                android:text="Februrary" />

                            <TextView
                                android:layout_width="0dp"
                                android:layout_weight="1"
                                android:background="@drawable/my_drawable"
                                android:gravity="center"
                                android:padding="15dip"
                                android:text="" />
                        </TableRow>
                    </TableLayout>

       </RelativeLayout>
 </ScrollView>
2

There are 2 answers

0
ben10 On
try this

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fillViewport="true"
    android:orientation="vertical">


    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"        android:orientation="vertical">



        <LinearLayout
            android:layout_height="match_parent"
            android:layout_width="match_parent"
            android:paddingLeft="@dimen/activity_horizontal_margin"
            android:paddingRight="@dimen/activity_horizontal_margin"
            android:paddingTop="@dimen/activity_vertical_margin"
            android:paddingBottom="@dimen/activity_vertical_margin"
            android:id="@+id/linearLayout1"
            android:orientation="vertical"
            android:layout_above="@+id/tableLayout"
            android:background="@android:color/darker_gray">
        </LinearLayout>


        <TableLayout
            android:id="@+id/tableLayout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@color/colorAccent"
            android:padding="5dp"
            android:layout_alignParentBottom="true">

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

                <TextView
                    android:id="@+id/home"
                    android:layout_width="0dp"
                    android:layout_weight="1"
                    android:background="@color/colorPrimary"
                    android:gravity="center"
                    android:padding="15dip"
                    android:text="Months" />

                <TextView
                    android:id="@+id/status"
                    android:layout_width="0dp"
                    android:layout_weight="1"
                    android:background="@color/colorPrimary"
                    android:gravity="center"
                    android:padding="15dip"
                    android:text="Number of Visits" />
            </TableRow>

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

                <TextView
                    android:layout_width="0dp"
                    android:layout_weight="1"
                    android:background="@color/colorPrimary"
                    android:gravity="center"
                    android:padding="15dip"
                    android:text="January" />

                <TextView
                    android:layout_width="0dp"
                    android:layout_weight="1"
                    android:background="@color/colorPrimary"
                    android:gravity="center"
                    android:padding="15dip"
                    android:text="1" />
            </TableRow>

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

                <TextView
                    android:layout_width="0dp"
                    android:layout_weight="1"
                    android:background="@color/colorPrimary"
                    android:gravity="center"
                    android:padding="15dip"
                    android:text="Februrary" />

                <TextView
                    android:layout_width="0dp"
                    android:layout_weight="1"
                    android:background="@color/colorPrimary"
                    android:gravity="center"
                    android:padding="15dip"
                    android:text="2" />
            </TableRow>
        </TableLayout>

    </LinearLayout>
</ScrollView>
0
Neo On

Why don't you apply ScrollView for Table only? This will only scroll the table and all views still displayed:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/webserviceLayout"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="#A3FFA3">

<!--Other layout -->
....................
    <ScrollView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@+id/tableInfo"
            android:isScrollContainer="true"
            android:paddingTop="2dp"
            android:paddingRight="2dp"
            android:paddingLeft="2dp"
            android:paddingBottom="2dp"
            >

            <HorizontalScrollView
                android:layout_width="match_parent"
                android:layout_height="wrap_content">

                <TableLayout
                    android:id="@+id/tablemaincontent"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:background="#E6E6E6" />
            </HorizontalScrollView>
        </ScrollView>
</RelativeLayout>