-1

I working on a project in which I have to make the whole activity scrollable but the scrollview and the gridview in conflicting. My code is not working properly.

So please sort out problem to how to make the whole page scrollable including the gridview.

Here is my code

<?xml version="1.0" encoding="utf-8"?>
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout 
 android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:background="@color/home_color">  
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        android:weightSum="6">
        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:orientation="vertical"
            android:layout_weight="2.2">
            <android.support.v4.view.ViewPager
                android:id="@+id/view_pager"
                android:layout_width="match_parent"
                android:layout_height="match_parent">
            </android.support.v4.view.ViewPager>
            <LinearLayout
                android:id="@+id/layoutDots"
                android:layout_width="match_parent"
                android:layout_height="40dp"
                android:layout_alignParentBottom="true"
                android:layout_marginBottom="10dp"
                android:layout_marginLeft="40dp"
                android:gravity="start"
                android:orientation="horizontal"/>              
        </RelativeLayout>
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:orientation="horizontal"
            android:background="@drawable/shadow"
            android:layout_marginLeft="10dp"
            android:layout_marginRight="10dp"
            android:layout_marginTop="10dp"
            android:layout_marginBottom="10dp"
            android:layout_weight="0.6">
            <TextView
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_weight="0.3"
                android:text="hhh"
                android:background="@android:color/holo_green_light"/>
            <TextView
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_weight="0.3"
                android:text="Personal Assistance"
                android:layout_gravity="center_vertical"
                android:gravity="center"
                android:textSize="16dp"/>
        </LinearLayout>
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_marginLeft="10dp"
            android:layout_marginRight="10dp"
            android:layout_marginTop="10dp"
            android:layout_marginBottom="10dp"
            android:background="@drawable/shadow"
            android:orientation="vertical"
            android:layout_weight="3.2">
            <GridView
                android:id="@+id/gridview"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:numColumns="2"
                android:verticalSpacing="5dp"
                android:horizontalSpacing="5dp"/>
        </LinearLayout>
    </LinearLayout> 
</LinearLayout> 
</ScrollView>
Vivek Kumar
  • 61
  • 1
  • 3
  • 5
    Possible duplicate of [How to put GridView inside ScrollView](http://stackoverflow.com/questions/12859250/how-to-put-gridview-inside-scrollview) – currarpickt Jul 28 '16 at 04:18

1 Answers1

4

You can try this.Your scroll view must have one parent layout

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="@color/home_color">  
  <ScrollView
   android:layout_width="match_parent"
   android:layout_height="match_parent">
   <LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:weightSum="6">
    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:orientation="vertical"
        android:layout_weight="2.2">
        <android.support.v4.view.ViewPager
            android:id="@+id/view_pager"
            android:layout_width="match_parent"
            android:layout_height="match_parent">
        </android.support.v4.view.ViewPager>
        <LinearLayout
            android:id="@+id/layoutDots"
            android:layout_width="match_parent"
            android:layout_height="40dp"
            android:layout_alignParentBottom="true"
            android:layout_marginBottom="10dp"
            android:layout_marginLeft="40dp"
            android:gravity="start"
            android:orientation="horizontal"/>              
    </RelativeLayout>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:orientation="horizontal"
        android:background="@drawable/shadow"
        android:layout_marginLeft="10dp"
        android:layout_marginRight="10dp"
        android:layout_marginTop="10dp"
        android:layout_marginBottom="10dp"
        android:layout_weight="0.6">
        <TextView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="0.3"
            android:text="hhh"
            android:background="@android:color/holo_green_light"/>
        <TextView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="0.3"
            android:text="Personal Assistance"
            android:layout_gravity="center_vertical"
            android:gravity="center"
            android:textSize="16dp"/>
    </LinearLayout>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_marginLeft="10dp"
        android:layout_marginRight="10dp"
        android:layout_marginTop="10dp"
        android:layout_marginBottom="10dp"
        android:background="@drawable/shadow"
        android:orientation="vertical"
        android:layout_weight="3.2">
        <GridView
            android:id="@+id/gridview"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:numColumns="2"
            android:verticalSpacing="5dp"
            android:horizontalSpacing="5dp"/>
    </LinearLayout>
</LinearLayout> 
</ScrollView>
</LinearLayout> 
Krishna Kachhela
  • 773
  • 1
  • 7
  • 24