0

I've got some linearlayouts and some views in my scrollview which covers the whole screen. The problem is that I can see that one of my widgets is under the screen and it won't scroll down. This is my xml file

<RelativeLayout 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"
    tools:context="${relativePackage}.${activityClass}" >

    <ScrollView
        android:id="@+id/mainScrollView"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:fillViewport="true"
        android:scrollbars="vertical" >

        <LinearLayout
            android:id="@+id/mainLayout"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:orientation="vertical" >

            <RelativeLayout
                android:id="@+id/topLayout"
                android:layout_width="match_parent"
                android:layout_height="wrap_content" >

                <TextView
                    android:id="@+id/textDateTime"
                    android:layout_width="wrap_content"
                    android:text="@string/nullString"
                    android:textAppearance="?android:attr/textAppearanceLarge"
                    android:textColor="#FFCCFF99"
                    android:textSize="25sp" />

                <LinearLayout
                    android:id="@+id/buttonsLayout"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_alignParentRight="true"
                    android:layout_margin="5dp"
                    android:orientation="horizontal" >

                    <Button
                        android:id="@+id/buttonReset"
                        style="?android:attr/buttonStyleSmall"
                        android:layout_width="130sp"
                        android:layout_height="40dp"
                        android:background="@drawable/button"
                        android:text="@string/buttonResetText"
                        android:textColor="#000000"
                        android:textSize="20sp" />

                    <Button
                        android:id="@+id/buttonFreeze"
                        style="?android:attr/buttonStyleSmall"
                        android:layout_width="130sp"
                        android:layout_height="40sp"
                        android:layout_marginLeft="5dp"
                        android:background="@drawable/button"
                        android:text="@string/buttonFreezeText"
                        android:textColor="#000000"
                        android:textSize="20sp" />
                </LinearLayout>
            </RelativeLayout>

            <ProgressBar
                android:id="@+id/loadBar"
                style="?android:attr/progressBarStyleLarge"
                android:layout_width="118dp"
                android:layout_height="118dp"
                android:layout_gravity="center" />

            <GridView
                android:id="@+id/sensorsGrid"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_margin="5dp"
                android:background="#FFCCFF99"
                android:gravity="center"
                android:numColumns="6"
                android:stretchMode="none" >
            </GridView>
        </LinearLayout>

    </ScrollView>

</RelativeLayout>

I also add a GraphView to mainLayout in code like this

graph = new LineGraphView(this, "GraphViewDemo");
graph.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, 300));
LinearLayout mainLayout = (LinearLayout) findViewById(R.id.mainLayout);
mainLayout.addView(graph);

Another problem is that if the GridView doesn't fit vertically to the mainlayout (cause it is larger) than the gridView becomes scrollable (which I don't want) and the GraphView which is below cannot be seen and I cant scroll down to it

UPDATE: current xml

<ScrollView
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    tools:context="${relativePackage}.${activityClass}"
    android:id="@+id/mainScrollView"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:fillViewport="true"
    android:scrollbars="vertical" >

        <LinearLayout
            android:id="@+id/mainLayout"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:background="#FF023458"
            android:orientation="vertical" >

            <RelativeLayout
                android:id="@+id/topLayout"
                android:layout_width="match_parent"
                android:layout_height="wrap_content" >

                <TextView
                    android:id="@+id/textDateTime"
                    android:layout_width="wrap_content"
                    android:layout_height="40dp"
                    android:layout_margin="5dp"
                    android:text="@string/nullString"
                    android:textAppearance="?android:attr/textAppearanceLarge"
                    android:textColor="#FFCCFF99"
                    android:textSize="25sp" />

                <LinearLayout
                    android:id="@+id/buttonsLayout"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_alignParentRight="true"
                    android:layout_margin="5dp"
                    android:orientation="horizontal" >

                    <Button
                        android:id="@+id/buttonReset"
                        style="?android:attr/buttonStyleSmall"
                        android:layout_width="130sp"
                        android:layout_height="40dp"
                        android:background="@drawable/button"
                        android:text="@string/buttonResetText"
                        android:textColor="#000000"
                        android:textSize="20sp" />

                    <Button
                        android:id="@+id/buttonFreeze"
                        style="?android:attr/buttonStyleSmall"
                        android:layout_width="130sp"
                        android:layout_height="40sp"
                        android:layout_marginLeft="5dp"
                        android:background="@drawable/button"
                        android:text="@string/buttonFreezeText"
                        android:textColor="#000000"
                        android:textSize="20sp" />
                </LinearLayout>
            </RelativeLayout>

            <ProgressBar
                android:id="@+id/loadBar"
                style="?android:attr/progressBarStyleLarge"
                android:layout_width="118dp"
                android:layout_height="118dp"
                android:layout_gravity="center" />

            <GridView
                android:id="@+id/sensorsGrid"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_margin="5dp"
                android:background="#FFCCFF99"
                android:gravity="center"
                android:numColumns="6"
                android:stretchMode="none" >
            </GridView>
        </LinearLayout>
</ScrollView>
pgSystemTester
  • 8,979
  • 2
  • 23
  • 49

2 Answers2

1

You should not add GridView inside ScrollView, because GridView itself is a scrollable view. A scrollable container inside another one will be taken over by the parent container (or vice versa) - causing not to scroll/appear properly on screen.

Tip: You should separate ScrollView and GridView. Or replace GridView with TableLayout.

waqaslam
  • 67,549
  • 16
  • 165
  • 178
  • thanks, Ill try it immediatally, but isnt there a way to remove "scrollability" from the gridView? because itll be better when the whole "screen" will be scrollable – Julius ShadowAspect Flimmel Jul 15 '14 at 12:41
  • removing scrolling ability from gridview will make it useless because its a recycling view. Instead, you should use TableLayout, which may act as gridview but without its own sroller. – waqaslam Jul 15 '14 at 12:43
  • @JuliusShadowAspectFlimmel : it's a hack here to override scrolling behavior http://stackoverflow.com/questions/6210895/listview-inside-scrollview-is-not-scrolling-on-android/14577399#14577399 – Arash GM Jul 15 '14 at 12:44
  • I suppose Ill have to bring back the relativeLayout which was on the top and put scrollView and gridView inside it ? – Julius ShadowAspect Flimmel Jul 15 '14 at 12:44
  • Do you need to show quite many items in GridView? if not, then I guess sticking to TableLayout would be sufficient enough. – waqaslam Jul 15 '14 at 12:48
  • no I dont have to, I will read something about the TableLayout, then Ill decide which one to use, since I am a little bit low on time and it is now working with your solution and gridview, so many thanks for the answer :) – Julius ShadowAspect Flimmel Jul 15 '14 at 12:53
0

change the scroll view tag to something like this, it will work for you.

<ScrollView
        android:id="@+id/mainScrollView"
        android:layout_width="fill_parent"
        android:layout_height="500dp"
        android:fillViewport="true"
        android:scrollbars="vertical" >
Pravinsingh Waghela
  • 2,516
  • 4
  • 32
  • 50