-4

We have used 4 Gridview in view, the problem is that when we try to make LinearLayout Scrollable its show scroll each gridview not single scroll on 1 view.

I need to make scrollable view instead of scrollable gridview.

Can anybody to see what i am doing wrong in this code.

<?xml version="1.0" encoding="utf-8"?>
<ScrollView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/scroll"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin">

    <LinearLayout
        android:id="@+id/container"
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <LinearLayout
            android:orientation="vertical"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/LinearFolders">

            <!--<RelativeLayout-->
                <!--android:orientation="horizontal"-->
                <!--android:layout_width="match_parent"-->
                <!--android:layout_height="match_parent"-->
                <!--android:padding="10dp">-->

                <!--<TextView-->
                    <!--android:text="Folders"-->
                    <!--android:layout_width="wrap_content"-->
                    <!--android:layout_height="wrap_content"-->
                    <!--android:id="@+id/Folders"-->
                    <!--android:layout_alignBaseline="@+id/toggleButtonFolders" />-->

                <!--<ToggleButton-->
                    <!--android:text="Toggle"-->
                    <!--android:layout_width="wrap_content"-->
                    <!--android:layout_height="wrap_content"-->
                    <!--android:id="@+id/toggleButtonFolders"-->
                    <!--android:layout_alignParentRight="true" />-->

            <!--</RelativeLayout>-->

            <GridView
                android:id="@+id/gvFolders"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:columnWidth="90dp"
                android:numColumns="auto_fit"
                android:verticalSpacing="10dp"
                android:horizontalSpacing="10dp"
                android:stretchMode="columnWidth"
                android:gravity="center"/>
        </LinearLayout>


        <LinearLayout
            android:orientation="vertical"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/LinearDocuments">



            <!--<RelativeLayout-->
                <!--android:orientation="horizontal"-->
                <!--android:layout_width="match_parent"-->
                <!--android:layout_height="match_parent"-->
                <!--android:padding="10dp">-->

                <!--<TextView-->
                    <!--android:text="Documents"-->
                    <!--android:layout_width="match_parent"-->
                    <!--android:layout_height="wrap_content"-->
                    <!--android:layout_alignBaseline="@+id/toggleButtonDocuments"-->
                    <!--android:id="@+id/txtDocuments" />-->


                <!--<ToggleButton-->
                    <!--android:text="Toggle"-->
                    <!--android:layout_width="wrap_content"-->
                    <!--android:layout_height="wrap_content"-->
                    <!--android:id="@+id/toggleButtonDocuments"-->
                    <!--android:layout_alignParentRight="true" />-->

            <!--</RelativeLayout>-->

            <GridView
                android:id="@+id/dvDocuments"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:columnWidth="90dp"
                android:numColumns="auto_fit"
                android:verticalSpacing="10dp"
                android:horizontalSpacing="10dp"
                android:stretchMode="columnWidth"
                android:gravity="center"/>
        </LinearLayout>


        <LinearLayout
            android:orientation="vertical"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/LinearImages">

            <!--<RelativeLayout-->
                <!--android:orientation="horizontal"-->
                <!--android:layout_width="match_parent"-->
                <!--android:layout_height="match_parent"-->
                <!--android:padding="10dp">-->

                <!--<TextView-->
                    <!--android:text="Images"-->
                    <!--android:layout_width="wrap_content"-->
                    <!--android:layout_height="wrap_content"-->
                    <!--android:id="@+id/txtImages"-->
                    <!--android:layout_alignBaseline="@+id/toggleButtonImages" />-->

                <!--<ToggleButton-->
                    <!--android:text="Toggle"-->
                    <!--android:layout_width="wrap_content"-->
                    <!--android:layout_height="wrap_content"-->
                    <!--android:id="@+id/toggleButtonImages"-->
                    <!--android:layout_alignParentRight="true" />-->

            <!--</RelativeLayout>-->

            <GridView
                android:id="@+id/dvImages"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:columnWidth="90dp"
                android:numColumns="auto_fit"
                android:verticalSpacing="10dp"
                android:horizontalSpacing="10dp"
                android:stretchMode="columnWidth"
                android:gravity="center"/>
        </LinearLayout>


        <LinearLayout
            android:orientation="vertical"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/LinearOthers">

            <!--<RelativeLayout-->
                <!--android:orientation="horizontal"-->
                <!--android:layout_width="match_parent"-->
                <!--android:layout_height="match_parent"-->
                <!--android:padding="10dp">-->

                <!--<TextView-->
                    <!--android:text="Others"-->
                    <!--android:layout_width="wrap_content"-->
                    <!--android:layout_height="wrap_content"-->
                    <!--android:id="@+id/txtOthers"-->
                    <!--android:layout_alignBaseline="@+id/toggleButtonOthers" />-->

                <!--<ToggleButton-->
                    <!--android:text="Toggle"-->
                    <!--android:layout_width="wrap_content"-->
                    <!--android:layout_height="wrap_content"-->
                    <!--android:id="@+id/toggleButtonOthers"-->
                    <!--android:layout_alignParentRight="true" />-->

            <!--</RelativeLayout>-->

            <GridView

                android:id="@+id/dvOthers"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:columnWidth="90dp"
                android:numColumns="auto_fit"
                android:verticalSpacing="10dp"
                android:horizontalSpacing="10dp"
                android:stretchMode="columnWidth"
                android:gravity="center"/>
        </LinearLayout>


    </LinearLayout>

</ScrollView>
  • 2
    you need to learn use of gridview functionality again – Ajay S Dec 19 '16 at 12:14
  • 2
    *Can anybody to see what i am doing wrong in this code.* You are putting scrollable(GridView) into scrollable(ScrollView). – Selvin Dec 19 '16 at 12:16
  • Nested scollables will give you headaches (scroll-handlers fighting). And nested layouts will give you bad performances. – Phantômaxx Dec 19 '16 at 12:25

3 Answers3

0
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/scroll"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin">

    <LinearLayout
        android:id="@+id/container"
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <LinearLayout
            android:orientation="vertical"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/LinearFolders">

            <!--<RelativeLayout-->
                <!--android:orientation="horizontal"-->
                <!--android:layout_width="match_parent"-->
                <!--android:layout_height="match_parent"-->
                <!--android:padding="10dp">-->

                <!--<TextView-->
                    <!--android:text="Folders"-->
                    <!--android:layout_width="wrap_content"-->
                    <!--android:layout_height="wrap_content"-->
                    <!--android:id="@+id/Folders"-->
                    <!--android:layout_alignBaseline="@+id/toggleButtonFolders" />-->

                <!--<ToggleButton-->
                    <!--android:text="Toggle"-->
                    <!--android:layout_width="wrap_content"-->
                    <!--android:layout_height="wrap_content"-->
                    <!--android:id="@+id/toggleButtonFolders"-->
                    <!--android:layout_alignParentRight="true" />-->

            <!--</RelativeLayout>-->

            <GridView
                android:id="@+id/gvFolders"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:columnWidth="90dp"
                android:numColumns="auto_fit"
                android:verticalSpacing="10dp"
                android:horizontalSpacing="10dp"
                android:stretchMode="columnWidth"
                android:gravity="center"/>
        </LinearLayout>

    </LinearLayout>

</ScrollView>

put like specific scrollview to all gridview so scroll in specific gridview.

Payal Sorathiya
  • 756
  • 1
  • 8
  • 23
0

You can achieve this in many ways.

Method 1 Set the height of GridView after setting the Adapter

Method 2 Create custom GridView which will adjust it's height based on child present

Method 3 (recommended) Use RecyclerView

Community
  • 1
  • 1
ShekharKG
  • 675
  • 6
  • 11
0

I have found the solution, we don't need to use multiple Gridview in signal view.

We are creating custom gridview with the list instead of default gridview. See github link this is helpful for me: https://github.com/velos/SectionedGrid